Ask HN: Where do I find good code to read?
As many have already said, what you&#x27;d consider &quot;good code&quot; depends on what you want to learn and achieve, but here are a few recommendations:<p>1. Busybox. It&#x27;s basically a collection of  common Unix utilities, from common commands like ls or cat, to system daemons like crond and init. It&#x27;s a good way to learn more about how Linux and other Unix-based systems work under the hood. Busybox applets are pretty independent from each other, so you can just take one and focus on it specifically, digging into the common library code if you need to. The utilities aren&#x27;t as fully-featured as their GNU coreutils counterparts, which makes it easier to understand what they actually do. Busybox is not a toy project by any means, though, it&#x27;s used in many embedded devices and leaner Linux distributions, Alpine being the prime example. However, it&#x27;s written in some pretty dense C, with a fair bit of pointer magic involved, so if you don&#x27;t understand things like the equivalence between a pointer and the beginning of an array, some things might not make sense.<p>2. The Go standard library. Unlike many programming languages, Go does not rely on much external code. Whereas Python delegates zip handling to zlib, handling of TLS connections to Openssl and so on, Go just includes all of this in the standard library, and it&#x27;s all pretty readable Go code. If you want to understand many common algorithms or file formats, everything from sorting arrays to parsing JSON to sending and receiving HTTP requests or common cryptographic operations, all written in a readable style, in a language much higher level than C, just look at the Go stdlib. Go even fully implements everything needed for its own compilation, including linkers and assemblers. I haven&#x27;t read these parts much, and a lot of that code is transpiled from C, so I can&#x27;t say how good the code quality is.<p>3. Serenity OS. It&#x27;s a hobby Posix-based operating system written in C++, with no external dependencies, not even libc or libstdc++. They have their own homegrown implementations of every part of an operating system, from a monolithic kernel, to common Unix utilities, archive handling, audio and video codecs, common data structures, like vectors (growable arrays), hash maps, locks,  mutexes and other concurrency primitives, a custom string implementation, a window server and a GUI library, including a fully-featured event loop system, their own window manager and many common GUI widgets, to actual applications and games. They even have a custom web browser with a custom web engine and JS interpreter. As a rule of thumb, if something it&#x27;s either in Busybox or in the Go standard library, there&#x27;s a good chance it will also be in Serenity. Again, their utilities do much less than their non-serenity counterparts and are far less optimized, but that also means there&#x27;s a lot fewer layers of abstraction to deal with and that the general principles underlying their implementation are actually easier to understand. The fact that everything is in a single repo, neatly organized, written in one language with common conventions, just makes it really pleasant to read. Their code quality isn&#x27;t always the best, but the fact that it&#x27;s C++ and not C does make things easier. Even though I haven&#x27;t actually used the OS (because of accessibility concerns), it&#x27;s one of these repos that I always have cloned on my computer, and it&#x27;s the first place I look if I&#x27;m curious how a particular feature or app can be implemented.<p>4. If you&#x27;re in any way interested in AI, everything written by Andrej Karpathy, notably Micrograd and Nano GPT. There&#x27;s also Tinygrad, a bigger but still understandable take on Micrograd. Unless you&#x27;re an expert, you need to watch Andrej&#x27;s Youtube videos to actually understand the code, but the feeling I got when I actually understood the principle behind Micrograd is one I will never forget. I consider it to be the most beautiful piece of code I&#x27;ve ever seen, it basically embodies the whole principle of what a neural net is in 200 lines of code. Everything else that the big libraries do is basically just implementations of actual models, optimization and glue code, such as for loading data and such. It&#x27;s often crucial optimization, optimization without which modern neural networks wouldn&#x27;t be possible at all, but just optimization nonetheless.<p>5. Everything concerning Elixir, both the standard library, other libraries written in it, as well as open-source Phoenix web apps. Deep down, it&#x27;s basically a Lisp without the off-putting parentheses. There are a lot of lessons to be learnt there, from the power of macros and the fact that things like &quot;if&quot; can be written in the language itself instead of being a special construct, to the power of pattern matching and the pipeline operator, to the advantages of its concurrency model and functional programming in general.<p>To generalize beyond these specific examples, if you want to understand something, find a smaller version of it, and try understanding that. The smaller version might just be a git commit from a good few years ago, with much fewer features, but it&#x27;s better if it is a different, more basic (but preferably not toy) implementation of the same app, feature or algorithm. Don&#x27;t read V8, PyTorch or Postgres, read Lua, Tinygrad or Sqlite instead.