
Ask HN: What are examples of GitHub repositories with high code quality? - baccheion
The language doesn&#x27;t really matter. I&#x27;m trying to see examples of what people consider high quality code (clean, elegant, well-formatted, algorithmically beautiful, etc).
======
forgotpwtomain
This isn't a github repo - but I think it's an excellent resource and worth
mentioning here: The Architecture of Open Source Applications
([http://aosabook.org/en/index.html](http://aosabook.org/en/index.html))

edit: I don't see why this is down-voted, the OP asked about examples of high-
quality code, structure and design are also a large part of this and it's not
hard to find the github-repo for any particular application mentioned in the
above book. Furthermore a lot of examples of excellent code are not
necessarily easy to approach with the 'open some random files and start
reading approach', having a high level overview often helps.

~~~
cheez
This is an excellent book, but the funny thing is that it only says "what is"
and not "why". It took me years of experience and pain to figure out "why".

~~~
aryamaan
Could you share some resources where "why" is also discussed.

~~~
cheez
Blood, sweat and tears are the only resources I have to offer...

------
tekacs
The Go standard library is throughly documented and implements all sorts of
functionality (HTTP, crypto, libc-esque functionality) in a fairly minimal
way:

[https://github.com/golang/go](https://github.com/golang/go)

~~~
edgyswingset
The APIs that you as the programmer are supposed to invoke tend to be well-
documented and fairly well-designed.

But there's some parts in there I certainly wouldn't call elegant. For
example, if you trace function calls from _http.Get()_ you end up in a lovely
function called _doFollowingRedirects()_ [0] which is where the actual request
is made inside of a _for {}_ loop.

Be it efficiency, some stylistic tendency I'm unaware of, or some contrived
excuse that doesn't make any sense, at the end of the day I'm not likely to
look for a function called _doFollowingRedirects_ when I want to see where the
initial (and likely only) request is made.

[0]:
[https://github.com/golang/go/blob/master/src/net/http/client...](https://github.com/golang/go/blob/master/src/net/http/client.go#L430)

~~~
tekacs
I read `doFollowingRedirects` with an elided comma - that is, 'do, following
redirects (as you go)'.

In that context, the function doesn't seem so surprising. If you take a look
at the function `Do`[0], you'll notice it calls out to either 'send' or
'doFollowingRedirects' depending on whether it's a request that should 'do,
following redirects' or simply 'send a single request'.

Many HTTP libraries I've seen are structured around creating a request object
and then handing it to a 'do request' function - the crime here at best seems
to be the naming 'doFollowingRedirects', which can be read as 'do the
subsequent redirects' which might make it seem odd that the first request was
included in the for loop therein.

------
if_by_whisky
Flask, which (for those that don't know) is a popular Python web framework.
[https://github.com/pallets/flask](https://github.com/pallets/flask)

I consider it well written. I never dive into flask and come out confused or
disappointed.

------
hthh
"High quality" is an strange concept. I would look at code you actually use
and rely on - that's the best indication of quality. A lot of critical code
deals with inelegant, complex problems correctly and efficiently - I'd
consider anything that can be relied on to manage that "high quality", even if
it is unclean, inelegant, poorly formatted and algorithmically mundane.

That said, if you want to read elegant code, I'd recommend the stb parser
libraries (written in C). They are small self-contained decoders for many
common media formats, with excellent documentation:

[https://github.com/nothings/stb/blob/master/stb_image.h](https://github.com/nothings/stb/blob/master/stb_image.h)
[https://github.com/nothings/stb/blob/master/stb_truetype.h](https://github.com/nothings/stb/blob/master/stb_truetype.h)
[https://github.com/nothings/stb/blob/master/stb_vorbis.c](https://github.com/nothings/stb/blob/master/stb_vorbis.c)

These libraries are likely insecure, handle many edge-cases incorrectly,
implement fewer features, and perform worse than other options. However, they
meet your criteria better.

~~~
sklogic
It is not nearly enough for a code to just work and be useful. Code quality is
what determines how maintainable it is, how long will it stay relevant, how
long will it survive the changing requirements and environment. And it is much
harder to get this than just something that (sometimes) work.

~~~
hthh
Absolutely, by all means look at old code - code that has survived and been
useful for a long time. It's either adaptable (Linux) or doesn't need to
change or adapt much (TeX).

Do you currently use and rely on software which you expect won't be useful to
you in ten years time? I can't think of much personally.

(I do use IDA Pro, which has clearly adapted poorly to changing requirements -
it still has scars of the 32-bit to 64-bit transition that get in the way of
day-to-day usage. I hope there'll be something better in ten years. Of course,
I could buy a cheaper, "higher quality" tool instead, but none of them are as
powerful or as useful.)

------
finishingmove
Question to C programmers: Every time I encounter some C code, it doesn't take
long until the obscurely short variable names start popping up from all
directions. Is naming variables in this manner considered acceptable by
today's "C best practices" or what's the deal with that?

~~~
kzhahou
Strangely, golang adopted this practice of very short variable names.
Surprising since golang is so focused on clarity and readability.

~~~
raverbashing
Exactly. The assumption that only long variables are readable is false

------
RobertKerans
For JavaScript, Underscore is very good in terms of clean readability. LoDash
is a better library, functionality-wise, but seems to have lost the quality
somewhat.

Backbone and the Coffeescript compiler are also good; jashkenas & the
contributors did a good job trying to put literary programming techniques to
use, IMO.

The Elixir source code is very high quality; same applies to the Ecto library.
Elixir code in general, because of the focus on including detailed
documentation (including doctests) within the code, tends to be very readable.
The way the REPL is set up means the docs for modules or functions can be
accessed at any point, so it's good for pragmatic reasons.

~~~
baby
[https://github.com/jashkenas/underscore/blob/master/undersco...](https://github.com/jashkenas/underscore/blob/master/underscore.js)

~~~
RobertKerans
Thanks, have crap WiFi ATM and can't get online for more than a few minutes at
a time, I'll add the rest of the links once I'm back in the UK

------
phaas
Here's a couple of projects that I've been personally impressed with. I hope
you don't mind a non-Github repo in there..

C

    
    
      - REDIS @ https://github.com/antirez/redis
      - Postgresql @ http://git.postgresql.org/gitweb/?p=postgresql.git;a=tree;f=src;hb=HEAD
    

Java

    
    
      - Spring Framework @ https://github.com/spring-projects/spring-framework
      - Guava @ https://github.com/google/guava
    

Javascript

    
    
      - ui-grid @ https://github.com/angular-ui/ui-grid

~~~
Bahamut
Can't say I agree personally on UI Grid - it's a bit of a mess in some ways,
especially in its distribution. It is also a bit of a configuration nightmare.

For high quality JS, I would look to some of the major frameworks out there:

[https://github.com/facebook/react](https://github.com/facebook/react)

[https://github.com/angular/angular.js](https://github.com/angular/angular.js)

[https://github.com/angular/angular](https://github.com/angular/angular)

There is a lot one can learn about software design by reading the source code
of major libraries, and is far more reliable than any third party library in
the ecosystem.

~~~
michaelchisari
A smaller, more accessible project would be Mithril, very nice, clean code. I
haven't looked at the v0.2 code yet, but I can't imagine it deviates much from
the quality of v0.1.

[https://github.com/lhorie/mithril](https://github.com/lhorie/mithril)

------
zerosign
I'm a bit surprise that no one actually mention rust programming language
codebase.

[https://github.com/rust-lang/rust](https://github.com/rust-lang/rust)

~~~
Manishearth
I'll note that while the code quality in Rust is pretty good (clean/usually
commented/well formatted/tested), it's not exactly idiomatic Rust.

This is because Rust as a language has changed a lot, and the compiler still
has old code that was written the "old way" and not updated to use better or
more idiomatic alternatives (e.g. elision, if let, etc). Servo is in a similar
situation. This is slowly improving as we run clippy on Rust and in occasional
manual refactorings (for example when sty was renamed to TypeVariants and
ty_foo was renamed to TyFoo to be have the correct capitalization -- the old
capitalization was _years_ old), but there still is work to do to make it
completely idiomatic.

So if you want to learn how to write idiomatic Rust, I would avoid using the
Rust repo as a source. Newer repos and new code in the Rust repo is pretty
okay, though.

------
elviejo
yegor from yegor256.com Did an award in 2015[0] for good quality software
projects. I think his evaluation points are sensible:

"Each project must be: * Open source (in GitHub). * At least 5,000 lines of
code. * At least one year old. * Object-oriented (that's the only thing I
understand).

The best projects will feature (more about it): * Strict and visible
principles of design. * Continuous delivery. * Traceability of changes. *
Self-documented source code. * Strict rules of code formatting.

What doesn't matter: * Popularity. * Programming language. * Buzz and trends.
"

In the end there 158 submissions, 12 finalist and 1 winner. Check them out.

[http://www.yegor256.com/2015/04/16/award.html](http://www.yegor256.com/2015/04/16/award.html)

~~~
franciscop
TL;DR (the article) this is the winner:

\-
[https://github.com/suseika/inflectible](https://github.com/suseika/inflectible)

------
jtolmar
Pokemon Showdown's code quality impressed me when I looked at it:
[https://github.com/Zarel/Pokemon-Showdown](https://github.com/Zarel/Pokemon-
Showdown)

It's not literally flawless (hard to find conceptual entry points, short on
comments), but when you get to the massive piles of one-off special functions
needed to simulate all of Pokemon's moves and abilities (e.g.
[https://github.com/Zarel/Pokemon-
Showdown/blob/master/data/a...](https://github.com/Zarel/Pokemon-
Showdown/blob/master/data/abilities.js) ) it's all much more succinct than I'd
have expected. The file I linked expresses more "business logic" in 3300 lines
than is contained in the entire 40kiloline codebases of some of the enterprise
monstrosities I've worked on.

~~~
partycoder
Code organization could use some work. A lot of shared mutable state. Event
listeners are subscribed with "on" instead of "once" for one time events...
that's all I could find in like 30 seconds... Disqualified

~~~
jack9
High Code Quality is not synonymous with perfect. Your critique is
disqualified.

------
notatoad
[https://github.com/tornadoweb/tornado](https://github.com/tornadoweb/tornado)
is one of my favourites. Not a huge number of comments, but in terms of "self-
documenting" code it's great.

~~~
hp
Seconded, it's a clean well-documented API with an implementation that's easy
to read.

------
hlieberman
[https://github.com/erlang/otp](https://github.com/erlang/otp) is one of the
best examples I can think of. It's reliability focused engineering from a
major engineering firm.

~~~
zorbash
I was hoping that i'd agree but check the code for Mnesia for example:
[https://github.com/erlang/otp/blob/maint/lib/mnesia/src/mnes...](https://github.com/erlang/otp/blob/maint/lib/mnesia/src/mnesia.erl#L1865)

Numerous functions missing essential code documentation all spread in a single
file, with commented out code committed in git.

------
adamkochanowicz
I'm surprised no one has mentioned
[https://github.com/twbs/bootstrap](https://github.com/twbs/bootstrap)

Maybe because it's getting a bad wrap these days with people doing dumb,
repetitive things with it. But I've always found the code quality to be very
good.

------
eulji
I would like to see people commenting about why they think that the project
they recommend has a high quality code.

Otherwise it's too subjective.

------
vonnik
I'm partial, because I work on these:

Deeplearning for Java
[https://github.com/deeplearning4j/deeplearning4j](https://github.com/deeplearning4j/deeplearning4j)

Scientific Computing for Java with n-dimensional arrays
[https://github.com/deeplearning4j/nd4j](https://github.com/deeplearning4j/nd4j)

The C++ lib that makes it fast
[https://github.com/deeplearning4j/libnd4j](https://github.com/deeplearning4j/libnd4j)

------
estreeper
I've really enjoyed looking at the GraphQL JavaScript reference implementation
source [1]. It is well-commented, consistently formatted and structured, and
makes frequent references to the spec. The spec itself [2] is very well
written too, and I think the project being spec-driven along with the code
quality make it a good example.

It feels like a _lot_ of thought was put in to making the code well-documented
and easy to follow for people new to the project.

[1] [https://github.com/graphql/graphql-
js](https://github.com/graphql/graphql-js) [2]
[https://facebook.github.io/graphql/](https://facebook.github.io/graphql/)

------
daurnimator
I was once searching for a "good" example of a code repository, but was unable
to find one I couldn't fault.

In response, I put the effort in for my smallest project to make it as high
quality as possible:
[https://github.com/daurnimator/fifo.lua](https://github.com/daurnimator/fifo.lua)

It's probably not much help to you unless you're working with lua; but... you
did say any language :)

------
dchest
[https://github.com/Tarsnap/spiped](https://github.com/Tarsnap/spiped)

------
raphaelsaunier
The Laravel framework [1]. It makes the most of the latest features available
in PHP (reflection, traits, namespacing, etc.) and its author, Taylor Otwell,
has an almost obsessive attitude with the naming of methods and formatting of
the source code. For instance, every multiline comment is exactly three lines
long, and every line is three characters shorter than the previous one [2].

[1]
[https://github.com/laravel/framework](https://github.com/laravel/framework)

[2]
[https://www.reddit.com/r/laravel/comments/20ovey/just_notice...](https://www.reddit.com/r/laravel/comments/20ovey/just_noticed_this_its_like_this_in_every_config/cg5w2x6)

~~~
raziel2p
Laravel is a pretty bad codebase, making use of reflection or just assuming
methods are present instead of interfaces, actively laughing in the face of
static typing.

They're also awful at managing issues/bugs, where they'll gladly close issues
without explanation, or close an issue when a pull request gets submitted,
only to reject the pull request and not re-open the issue.

~~~
raphaelsaunier
Fair enough, you seem to have contributed quite a bit to the framework after
all [1]. However, don't you think they have gotten better with triaging as of
late?

Also, I'm wondering, does your criticism still apply to the latest versions of
Laravel or does it stem from frustrations with the pre-5.0 versions? Regarding
your comments about the lack of interfaces, it's worth mentioning that at
least the core components do have an interface now [2].

[1]
[https://github.com/laravel/framework/pulls?utf8=%E2%9C%93&q=...](https://github.com/laravel/framework/pulls?utf8=%E2%9C%93&q=is%3Apr+author%3Aanlutro)

[2] [https://laravel.com/docs/master/contracts#contract-
reference](https://laravel.com/docs/master/contracts#contract-reference)

------
killercup
This is beautiful: [https://github.com/rust-lang-
nursery/regex/blob/master/src/d...](https://github.com/rust-lang-
nursery/regex/blob/master/src/dfa.rs)

------
iurisilvio
Any Python code from Armin Ronacher
([https://github.com/mitsuhiko](https://github.com/mitsuhiko)) or Kenneth
Reitz ([https://github.com/kennethreitz](https://github.com/kennethreitz)).

They have really clean code, popular packages and are open about their
decisions. It is interesting to understand their design thinking.

------
JimRoepcke
[https://github.com/yapstudios/YapDatabase](https://github.com/yapstudios/YapDatabase)

Great code, docs and support.

------
jpetitto
Any of the popular Square libraries are great examples,
[https://github.com/square](https://github.com/square).

------
troika
Both the deepstream.io server

[https://github.com/deepstreamIO/deepstream.io](https://github.com/deepstreamIO/deepstream.io)

And node client

[https://github.com/deepstreamIO/deepstream.io-client-
js](https://github.com/deepstreamIO/deepstream.io-client-js)

are examples for a very clean, "no nonsense" style of writing JavaScript

~~~
partycoder
Uses JSDoc, and the code is well structured.

But it has lots of statefulness, some of the state is structured as a finite
state machines in ways that are easy to break (similar to the "request"
module, also a FSM that is incredible easy to break).

Function parameters are not validated.

~~~
gbrits
What do you mean by breaking the fsm? Isn't the whole point of having a fsm to
explicitly describe the entire app-state? Honest question

~~~
partycoder
A state machine has states and transitions. Some transitions are valid, others
are not.

Therefore when you implement a state machine in code the consequence is
sequential coupling.

Imagine a car class: You have StartCar(), Accelerate(), Break(), StopCar(),
SwitchGear(). Can you accelerate with your car turned off? no. Can you stop
your car twice? No. So there should be validations in state transitions. Since
in this code those are missing, it's possible to arrive to invalid states that
can cause undesired behavior.

In the "request" npm module (an ambiguous module name that wastes a lot of my
time in a regular basis), you can abort a request that has not started. That
causes an exception. It took me a lot of time to find it. It was all because
of a broken state machine.

------
noir_lord
[https://github.com/laravel/framework/tree/5.2/src/Illuminate](https://github.com/laravel/framework/tree/5.2/src/Illuminate)

It's one of the highest quality and cleanest PHP codebases I've ever seen.

PS: Please pipe all the unflattering comments about PHP to /dev/null, heard
them all before.

------
cjcenizal
[https://github.com/smaato/ui-framework](https://github.com/smaato/ui-
framework)

UI Framework built with React and SCSS. The components are nicely modularized,
have unit tests, and we put a lot of emphasis on code readability, clear names
for things, a scalable folder structure, and intuitive interfaces.

------
elliotec
[https://github.com/thoughtbot](https://github.com/thoughtbot)

------
bluetomcat
The Quaint programming language:

[https://github.com/bbu/quaint-lang](https://github.com/bbu/quaint-lang)

I think the strengths of the C code are: straightforward algorithms without
many nonsensical abstraction layers, consistent and clean formatting, sane
usage of the preprocessor.

------
myko
[https://github.com/ReactiveCocoa/ReactiveCocoa](https://github.com/ReactiveCocoa/ReactiveCocoa)

IMO very well written and very well run project. I follow most issues closely
just because the discussions re: code reviews, new features, and community
questions.

~~~
afro88
And a very nicely written and architected example project:

[https://github.com/richeterre/SwiftGoal](https://github.com/richeterre/SwiftGoal)

ReactiveCocoa 4, Swift 2.2, MVVM architected, full test suite.

------
personjerry
Nethack's repository is pretty great, especially considering how old it is and
that it is in C.

[https://github.com/Vanilla-
NetHack/NetHack/tree/master/src](https://github.com/Vanilla-
NetHack/NetHack/tree/master/src)

~~~
akx
I... is that sarcasm? NetHack's code is a tangled mess of K&R C.

~~~
riffraff
indeed it seems it's often a sea of nested if's and switch's with occasional
#ifdef's e.g. [https://github.com/Vanilla-
NetHack/NetHack/blob/master/src/a...](https://github.com/Vanilla-
NetHack/NetHack/blob/master/src/apply.c#L277)

I think this is a reasonable way to handle the tons of special cases in
nethack's gameplay, but not really "inspiring".

------
sklogic
The threshold of what the high code quality is was set long ago and remains
far beyond the reach of the mere mortals.

You will hardly find anything even distantly approaching the quality of TeX
and Metafont. Not sure if there are mirrors on github, but you can always grab
a copy from CTAN.

------
robuon619
The LMAX Disruptor is well-documented, fast, and arguably simple considering
what it offers: [https://github.com/LMAX-
Exchange/disruptor](https://github.com/LMAX-Exchange/disruptor)

~~~
ruraljuror
There are a couple of good episodes of software engineering radio to go along
with this codebase.

------
berfarah
Hanami has really good code quality: it's really easy to understand from a
newcomer's perspective and is full of examples:
[https://github.com/hanami](https://github.com/hanami)

------
lambdafunc
Presto has great source code too, check it out:
[http://github.com/prestodb/presto](http://github.com/prestodb/presto)

------
sairamkunala
Spree has followed very good standards -
[https://github.com/spree/spree](https://github.com/spree/spree)

Language: Ruby Framwork: Rails

------
partycoder
Id Software's Doom 3: [https://github.com/id-
Software/DOOM-3](https://github.com/id-Software/DOOM-3)

~~~
iso-8859-1
Isn't game code notorious for being hastily finished?

------
TheAceOfHearts
lodash is great and heavily documented.

[0] [https://github.com/lodash/lodash/](https://github.com/lodash/lodash/)

------
devcheese
[https://github.com/stripe/stripe-go](https://github.com/stripe/stripe-go)

------
pmarin
NetBSD

[https://github.com/IIJ-NetBSD/netbsd-src](https://github.com/IIJ-
NetBSD/netbsd-src)

------
doubleagent
Ring is pretty special.

[https://github.com/ring-clojure/ring](https://github.com/ring-clojure/ring)

------
roschdal
[https://github.com/torvalds/linux](https://github.com/torvalds/linux)

~~~
loosescrews
Have you actually ever read any of the Linux source code? I find it pretty
hard to read to be honest. There are barely any comments and the ones that are
there are often not very helpful.

~~~
yzh
I highly recommend this gitbook to you: [https://0xax.gitbooks.io/linux-
insides/content/index.html](https://0xax.gitbooks.io/linux-
insides/content/index.html)

~~~
ewjordan
"Read the docs" is not an excuse for incomprehensible source code. If links to
documentation are not in the code, they might as well be nonexistent.

In this case, I've never read the sources, so I have no idea if the complaint
is valid.

~~~
simoncion
> If links to documentation are not in the code, they might as well be
> nonexistent.

Yeesh. I must either be getting old, or everyone is _significantly_ more busy
than I am. I find that I always have time to at least _locate_ any official
documentation for the thing that I'm working with.

------
hath995
[https://github.com/hapijs/hapi](https://github.com/hapijs/hapi)

------
vjdhama
crystal-lang's standard library is a good example.
[https://github.com/crystal-lang/crystal](https://github.com/crystal-
lang/crystal)

------
bobwaycott
Elixir and Phoenix

------
franciscop
I'm going to propose one of my own[1], since I can do few projects without
time limit (for fun) so I did my best to properly program, test and document
it. I overcommented on the past but I'm trying to correct it now. Also, all of
the new contributors follow the same style so things stay consistent. As an
example, let's try to understand the function `.addClass`:

\- Just to use it you can see the documentation on the website[2], which is
the first contact normally.

\- Then when you try to find the relevant files. They are in github's
`src/plugins/addclass`, a name that is common and intuitive [3].

\- Not only that, but you also got the documentation in that folder in github
thanks to the name `readme.md`.

\- When opening it [4], the first thing that you note is that the function has
a tiny footprint; 8 lines. A brief explanation of what it does and a line
explaining what the not-so-intuitive function `this.eacharg()` means.

\- Then we use the native `Element.classList` [5] to add classes. Most people
familiar with _vanilla_ javascript know it, but otherwise the name is quite
descriptive `el.classList.add(name)`

In contrast, while covering quite few other edge cases and older browsers,
check jQuery's `.addClass()` code [6]. Or check Zepto.js' `addClass()` code
[7]

[1]
[http://github.com/umbrellajs/umbrella/](http://github.com/umbrellajs/umbrella/)

[2]
[http://umbrellajs.com/documentation#addclass](http://umbrellajs.com/documentation#addclass)

[3]
[https://github.com/umbrellajs/umbrella/tree/master/src/plugi...](https://github.com/umbrellajs/umbrella/tree/master/src/plugins/addclass)

[4]
[https://github.com/umbrellajs/umbrella/blob/master/src/plugi...](https://github.com/umbrellajs/umbrella/blob/master/src/plugins/addclass/addclass.js)

[5]
[https://developer.mozilla.org/en/docs/Web/API/Element/classL...](https://developer.mozilla.org/en/docs/Web/API/Element/classList)

[6]
[https://github.com/jquery/jquery/blob/305f193aa57014dc7d8fa0...](https://github.com/jquery/jquery/blob/305f193aa57014dc7d8fa0739a3fefd47166cd44/src/attributes/classes.js#L17)

[7]
[https://github.com/madrobby/zepto/blob/601372ac4e3f98d502c70...](https://github.com/madrobby/zepto/blob/601372ac4e3f98d502c707bf841589fbc48a3a7d/src/zepto.js#L732)

