Ask HN: What's the best source code you've read?

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • Case in point, Microsoft develops an editor (VSCode) and LSP so that N*M language integrations wouldn't be necessary. But in the development of their language (TypeScript), LSP support is not a priority: https://github.com/microsoft/TypeScript/issues/39459

  • LevelDB

    LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • Django

    The Web framework for perfectionists with deadlines.

  • I will always have a soft spot in my heart for Django, the python web framework, even though I don’t use it anymore. https://www.djangoproject.com/

    When I was still learning to code, I spent hours and hours and hours poking around the Django source code. In particular I was fascinated by the metaprogramming used in the Model and Query objects, and I ended up learning a ton about how Python works under the hood.

  • mikeOS

    Mirror for MikeOS 4.5 - Simple and educational Operating System written by Mike Saunders

  • The 8086 Assembly source code of the MikeOS operating system is remarkably readable and easy to understand for such low-level software http://mikeos.sourceforge.net

  • sokol

    minimal cross-platform standalone C headers

  • Recently I've enjoyed reading the source code to Sokol, lot's of really good decisions there and I love the minimal C -style structure:

    https://github.com/floooh/sokol

  • Polly

    Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.

  • I don't know if it is the most elegant, or concise, or l33t, but I am in love with Polly https://github.com/App-vNext/Polly

  • Lua

    Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • ripgrep

    ripgrep recursively searches directories for a regex pattern while respecting your gitignore

  • freebsd-src

    The FreeBSD src tree publish-only repository. Experimenting with 'simple' pull requests....

  • I quite like the FreeBSD src tree, as it comprises both the system kernel as well as the userland applications. The folders are organized similarly to the OS file system hierarchy, which I find helpful for navigating the source tree. I found it accessible to slowly learn how various parts of the OS work under the hood and compound my knowledge faster due to less context shifting, since it’s self-contained in one source tree.

    https://github.com/freebsd/freebsd-src

  • webtorrent

    ⚡️ Streaming torrent client for the web

  • Redis

    Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.

  • tinygrad

    Discontinued You like pytorch? You like micrograd? You love tinygrad! ❤️ [Moved to: https://github.com/tinygrad/tinygrad] (by geohot)

  • Since diving into stable diffusion, I found the original code not very well organized not factored.

    Then trying and looking at https://github.com/geohot/tinygrad which can implement SD, it’s really well written and ideas well organized, concise, and it works on multiple platforms well.

  • source-sdk-2013

    The 2013 edition of the Source SDK

  • I had quite some pleasure working with the Source Engine gameplay code. (Some 10 years ago now)

    https://github.com/ValveSoftware/source-sdk-2013

    It is not that the quality of the code is high, but just that it is well organized, and everything seems like it was written by a beginner. That makes it wonderfully easy to read and follow the logic.

    Since have played around with the Source Engine, I follow the KISS principle with coding with high priority. Rarely trying to be clever, or try to over-do abstractions.

  • mpv

    🎥 Command line video player

  • I'm probably biased, but I particularly enjoyed going through mpv - https://github.com/mpv-player/mpv

    I always found much of the FFmpeg API very unintuitive and I much of what I know about it now I learned from reading through mpv. Hardware accelerated encode/decode, etc.

  • Principia

    𝑛-Body and Extended Body Gravitation for Kerbal Space Program

  • I haven’t read all of it, but the Principia source code has a comprehensive units system and makes effective use of Unicode: https://github.com/mockingbirdnest/Principia/

    https://github.com/mockingbirdnest/Principia/blob/master/ast... is a decent example of both:

        // We compute the mean rate (slope) of the mean anomaly M(t), the mean

  • pcgeos

    #FreeGEOS source codes. The offical home of the PC/GEOS operating system technology. For personal computing fans. For all developers and assembly lovers. For YOU!

  • tunguska

  • I think my code is regressing:

    C++ from 14 years ago:

    https://github.com/vlofgren/tunguska/blob/master/tunguska_3c...

    A career of Java development later, and the code I wrote yesterday looks like this:

    https://git.marginalia.nu/marginalia/marginalia.nu/src/commi...

  • binjgb

    Gameboy emulator implemented in C, that also runs in the browser

  • quickjs

    Public repository of the QuickJS Javascript Engine.

  • kivaloo

    Kivaloo is a collection of utilities which together form a data store associating keys of up to 255 bytes with values of up to 255 bytes.

  • cperciva writes easily the most approachable, understandable code I’ve ever come across, e.g.:

    https://github.com/tarsnap/kivaloo

  • serenity

    The Serenity Operating System 🐞

  • My favourite is SerenityOS: https://github.com/SerenityOS/serenity

    Not only is the code itself structured much more pleasantly than I ever suspected possible in C++, huge parts of it were also recorded while they were being written (see https://www.youtube.com/c/AndreasKling) so you can see and hear the process that led to the final product.

    Some of the code is quite gnarly, which is to be expected from a repo containing an entire operating system, containing everything from the kernel to a bespoke web browser.

    However, as SerenityOS isn't trying to be a UNIX clone, its C++ oriented APIs are a nice breath of fresh air compared to the barebones C that Linux and friends use.

  • lightning

    Core Lightning — Lightning Network implementation focusing on spec compliance and performance

  • NetHack

    Official NetHack Git Repository

  • v3-core

    🦄 🦄 🦄 Core smart contracts of Uniswap v3

  • Recently my favorite is core contracts of Uniswap V3 - https://github.com/Uniswap/v3-core Lots of nice ideas for a restrictive computing platform like EVM.

  • blender

    Official mirror of Blender

  • I found the Blender codebase very intriguing. Overall just amazing piece of software and lots to learn from https://github.com/blender/blender.

  • swift

    The Swift Programming Language

  • Apple's Swift source looks nice[0]. So does Darwin[1].

    They have done a lot of work on structure and documentation, since the docs are auto-generated.

    I have taken a lot of inspiration from them.

    The Adobe APIs[2] were also excellent, but I'm not sure they are open for browsing, anymore.

    [0] https://github.com/apple/swift

    [1] https://github.com/apple/darwin-xnu

    [2] https://developer.adobe.com/photoshop/api/

  • darwin-xnu

    Discontinued Legacy mirror of Darwin Kernel. Replaced by https://github.com/apple-oss-distributions/xnu

  • Apple's Swift source looks nice[0]. So does Darwin[1].

    They have done a lot of work on structure and documentation, since the docs are auto-generated.

    I have taken a lot of inspiration from them.

    The Adobe APIs[2] were also excellent, but I'm not sure they are open for browsing, anymore.

    [0] https://github.com/apple/swift

    [1] https://github.com/apple/darwin-xnu

    [2] https://developer.adobe.com/photoshop/api/

  • tcl

    The Tcl Core. (Mirror of core.tcl-lang.org) (by tcltk)

  • I've never seen C code as clear and well documented as tcl. E.g. https://github.com/tcltk/tcl/blob/main/generic/tclUtil.c, though more examples in that project are not hard to find.

  • GladiatorPits-MUD

    The source code behind Richard Woolcock's Gladiator Pits.

  • nsis

    ***This is just a mirror of https://sf.net/projects/nsis -- please report issues there*** NSIS (Nullsoft Scriptable Install System) is a professional open source system to create Windows installers. It is designed to be as small and flexible as possible and is therefore very suitable for internet distribution.

  • Eye-opening but probably not "best": the Nullsoft Installer, circa 2002 (https://github.com/kichik/nsis). Its goal, besides being an installer, was to produce a small binary. So the source was remarkably pithy, which taught me a lot about being direct and to-the-point rather than aiming for beautiful abstractions or reusability.

    Similar with Notch's Left4KDead, which implemented a fun zombie game for a Java small-code competition. A mirror of the original source is here (https://github.com/codingcampbell/Left-4k-Dead). I rewrote it in JavaScript as a Chrome App, in the process refactoring for readability (and sacrificing some of the code's beauty). https://github.com/sowbug/ChromeLeft4kDead

  • Left-4k-Dead

    Mirror of Notch's L4KD code

  • Eye-opening but probably not "best": the Nullsoft Installer, circa 2002 (https://github.com/kichik/nsis). Its goal, besides being an installer, was to produce a small binary. So the source was remarkably pithy, which taught me a lot about being direct and to-the-point rather than aiming for beautiful abstractions or reusability.

    Similar with Notch's Left4KDead, which implemented a fun zombie game for a Java small-code competition. A mirror of the original source is here (https://github.com/codingcampbell/Left-4k-Dead). I rewrote it in JavaScript as a Chrome App, in the process refactoring for readability (and sacrificing some of the code's beauty). https://github.com/sowbug/ChromeLeft4kDead

  • ChromeLeft4kDead

    Notch's Left4kDead as a Chrome App.

  • Eye-opening but probably not "best": the Nullsoft Installer, circa 2002 (https://github.com/kichik/nsis). Its goal, besides being an installer, was to produce a small binary. So the source was remarkably pithy, which taught me a lot about being direct and to-the-point rather than aiming for beautiful abstractions or reusability.

    Similar with Notch's Left4KDead, which implemented a fun zombie game for a Java small-code competition. A mirror of the original source is here (https://github.com/codingcampbell/Left-4k-Dead). I rewrote it in JavaScript as a Chrome App, in the process refactoring for readability (and sacrificing some of the code's beauty). https://github.com/sowbug/ChromeLeft4kDead

  • poly

    A Go package for engineering organisms.

  • Not that I understand any of the organic science behind it, but Timothy Stiles' Poly is some of the most beautiful Go code I've seen: https://github.com/TimothyStiles/poly

    Blew my mind reading through it, honestly. Just perfect.

  • RetroArch

    Cross-platform, sophisticated frontend for the libretro API. Licensed GPLv3.

  • I found the RetroArch source (https://github.com/libretro/RetroArch) very accessible, when I added a simple title sanitisation it was easy to figure out what I had to change and where the changes needed to be. The accessibility of the source was particularly helpful as it was the first non-trivial C code I had come in contact with.

  • chips

    8-bit chip and system emulators in standalone C headers

  • I don't know if it's the best code I've ever read but this emulation library [0] of 8 bits computers is pretty well written, documented and designed: https://github.com/floooh/chips.

    It's a good way to document old hardware with emulation code.

  • PostgreSQL

    Mirror of the official PostgreSQL GIT repository. Note that this is just a *mirror* - we don't work with pull requests on github. To contribute, please see https://wiki.postgresql.org/wiki/Submitting_a_Patch

  • PostgreSQL comes to mind (eg: see the query planner [0]). It is surprisingly easy to read through lots of interesting parts and see how they are working.

    [0] https://github.com/postgres/postgres/blob/master/src/backend...

  • espanso

    Cross-platform Text Expander written in Rust

  • Julia mode for Emacs, Vim, and VSCode lets you to use LaTeX-like sequences: write \pm, press , and you get ±

    Of course, this only works if your editor supports this and you are using a language similar to Julia. But there are two more general methods that are applicable everywhere. The first was mentioned by db48x: I have customized my Xmodmap file so that greek letters and a few typographic characters I use often can be typed using AltGr combinations. (Unfortunately, this is much more complicated if you use Windows.)

    Secondly, I heavily use Espanso [1], so that I can easily type complicated letters/sequences (e.g., my email address) for which it would be too overkill to assign an AltGr keybinding.

    Finally, in Emacs and Kitty (my terminal emulator) there is a keybinding that asks for the name of an Unicode symbol and enters it. (In Emacs it's C-x 8 , in Kitty Shift+Ctrl+u.)

    From the point of view of my workflow, the problem of quickly typing Unicode characters is completely solved.

    [1] https://espanso.org/

  • Wt

    Wt, C++ Web Toolkit

  • Linux Kernel source is very good.

    Wt[0] source code is also good.

    [0] https://github.com/emweb/wt

  • LibVF.IO

    A vendor neutral GPU multiplexing tool driven by VFIO & YAML.

  • Perhaps not the "best" source code I've ever read, but libVF.io had some beautiful code for what's generally gnarly system-glue code. The iommu setup code is a good example and inspires me to think that system-glue code doesn't need to be gross or impenetrable: https://github.com/Arc-Compute/LibVF.IO/blob/master/src/libv...

    Another one I've appreciated reading (and learned more about 2d graphics from) is Pixie, a 2d graphics library written in Nim. Here's the implementation of a fair subset of SVG paths: https://github.com/treeform/pixie/blob/master/src/pixie/path...

    And one last one for basic algorithms: https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/al...

    Of course Knuth's original code is still some of the best classic code. K&R's original C book is a classic.

  • pixie

    Full-featured 2d graphics library for Nim. (by treeform)

  • Perhaps not the "best" source code I've ever read, but libVF.io had some beautiful code for what's generally gnarly system-glue code. The iommu setup code is a good example and inspires me to think that system-glue code doesn't need to be gross or impenetrable: https://github.com/Arc-Compute/LibVF.IO/blob/master/src/libv...

    Another one I've appreciated reading (and learned more about 2d graphics from) is Pixie, a 2d graphics library written in Nim. Here's the implementation of a fair subset of SVG paths: https://github.com/treeform/pixie/blob/master/src/pixie/path...

    And one last one for basic algorithms: https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/al...

    Of course Knuth's original code is still some of the best classic code. K&R's original C book is a classic.

  • Nim

    Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).

  • Perhaps not the "best" source code I've ever read, but libVF.io had some beautiful code for what's generally gnarly system-glue code. The iommu setup code is a good example and inspires me to think that system-glue code doesn't need to be gross or impenetrable: https://github.com/Arc-Compute/LibVF.IO/blob/master/src/libv...

    Another one I've appreciated reading (and learned more about 2d graphics from) is Pixie, a 2d graphics library written in Nim. Here's the implementation of a fair subset of SVG paths: https://github.com/treeform/pixie/blob/master/src/pixie/path...

    And one last one for basic algorithms: https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/al...

    Of course Knuth's original code is still some of the best classic code. K&R's original C book is a classic.

  • Smalltalk

    By the Bluebook implementation of Smalltalk-80

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts