22 ms·
Ask HN: What are the “best” codebases that you've encountered?
I am rather fond of the concepts described in "Clean Code" by Robert Martin but it seems that in real life, a really high-quality codebase is hard to come by.
While I am asking myself this question, the only one that popups to my mind would be Laravel: https://github.com/laravel/laravel (PHP)
One could think that a codebase as popular as React (https://github.com/facebook/react) would be a perfect example of "clean code" but with a glance, I personally don't find it very expressive.
This may all be very subjective but I would love to see examples of codebases that member of this community have enjoyed working with
- billconan 7y agoQt's codebase is very clean
- steveschilz 7y agoI love Qt, and Qt has a great cross platform API. However Qt uses a lot of Qt-Only idioms, in particular there is has simplified memory management based on parent/child relationships (all children are deleted with parents), and also "COW" copy on write containers that can simplify programming but make it harder to reason about memory allocation. Further, all internal classes also include a PIMPL (d-pointer or data pointer) to hide internal details from API customers. IMO, The d-pointer makes stuff much more difficult to read, and the Qt idioms are probably only useful if you are a Qt developer. So maybe might not be useful for you if you are on a non-Qt project.
- phkahler 7y agoI thought QT was a collection of libraries, even with different licenses. As such, it seems strange to apply a word like "clean" to the whole thing.
- johannes1234321 7y agoQt core and most libraries are written by the same group of people in the same development process. Splitting it up into libraries is good engineering practice as it ensures boundaries. (Whether it is packaged into their own dll/so/a/dynlib is a deployment question, you can compile all parts statically together) The licensing is a political/business question independent from code being nice, good and clean. (Except one has to be careful during refactorings, as code might change license, but since afaik the Qt Company has CLAs ensuring copyright ownership they are able to do that)
- halleonard 7y agoThe Gatsby codebase is dreamy https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby https://github.com/gatsbyjs/gatsby/tree/master/packages/gats...
- lugg 7y agoI'm really curious how you see laravel as a shining example of clean code? That thing is the epitome of a framework for frameworks sake. Pretty sure Most of Martin's talks begin by complaining about this sort of thing?
- whycombagator 7y ago> That thing is the epitome of a framework for frameworks sake. Go on
- astrange 7y agoAny PHP framework is a case of inner-platform: https://en.wikipedia.org/wiki/Inner-platform_effect https://en.wikipedia.org/wiki/Inner-platform_effect PHP already is the "framework" and every time you load a page it's executing the script from scratch. You're wasting a lot of time loading a framework to handle control flow for your program which doesn't have any control flow in the first place.
- whycombagator 7y agoI'm not a PHP dev, but I've dabbled. And I'm not sure I follow. How is it a framework for frameworks sake? I take that to mean it's pointless/not useful. Whereas I'd say Laravel and it's ecosystem are far more productive and time saving than simply using just PHP. It's the opposite of wasting time. From their github repo[0] Laravel has: - Simple, fast routing engine. - Powerful dependency injection container. - Multiple back-ends for session and cache storage. - Expressive, intuitive database ORM. - Database agnostic schema migrations. - Robust background job processing. - Real-time event broadcasting. Not only is it a robust, pleasant, framework with batteries included but there's also an entire ecosystem/platform of related products that are pretty big time savers: spark[1], forge[2], envoyer[3], and horizon[4]. And, as an aside, the documentation is good and there are some pretty great tutorials too[5] What am I missing? [0] https://github.com/laravel/laravel https://github.com/laravel/laravel [1] https://forge.laravel.com/ https://forge.laravel.com/ [2] https://spark.laravel.com/ https://spark.laravel.com/ [3] https://envoyer.io/ https://envoyer.io/ [4] https://horizon.laravel.com https://horizon.laravel.com [5] https://laracasts.com/ https://laracasts.com/
- e9 7y agoffmpeg https://github.com/FFmpeg/FFmpeg https://github.com/FFmpeg/FFmpeg
- gnulinux 7y agoRecently had to make a few changes to ffmpeg codebase. It's pretty good.
- astrange 7y agoThe build system and assembly system (x86asm) are very underrated. Open source went from autotools, which are awful, to cmake, which also seems to be awful. ffmpeg's configure/make system has the same interface as autotools but is actually good. libavformat is rather difficult to use and difficult to fix bugs in - you'll never find the bugs. Same with the ffmpeg frontend, which makes it easy to ask for something it's near impossible to get right, like copying an mkv file to an avi, it'll just corrupt your data silently. Everything about the video decoders is great, but encoding never worked as well, which is why nobody uses ffmpeg2/4/etc and x264 is a separate project.
- _Gyan_ 7y agolibavformat is rather difficult to use and difficult to fix bugs in - you'll never find the bugs. Some examples? encoding never worked as well, which is why nobody uses ffmpeg2/4/etc and x264 is a separate project. Most users use x264 _via_ ffmpeg since they may need to filter the video and/or filter/process/mux audio and other streams.
- astrange 7y ago> Some examples? Just try copying video between different containers (mkv, ts, avi for one) without reencoding. > Most users use x264 _via_ ffmpeg since they may need to filter the video and/or filter/process/mux audio and other streams. They don't have to do that; you can handle each track separately and mux them back afterward. I'm talking about ffmpeg's builtin MPEG2/4/MP3 encoders, which nobody used when they were competitive because it leaves all the options at "go fast" instead of providing tunings. They're also unmaintained and the code is hard to figure out - that's why x264 was a separate project instead of just another part of libavcodec.
- coleifer 7y agoI know it's a cliche but the sqlite code is the easiest to read C I've encountered. Followed closely by the code for Redis.
- sea6ear 7y agoI also like the C source for Tcl/Tk which I think also follows similar engineering/style standards.
- noir_lord 7y agoThe author of Tcl/Tk wrote a fantastic book recently called "A Philosophy of Software Design" and it's brilliant, hands down my favourite programming book of the last decade.
- bch 7y agoTcl/Tk is listed below by others, but it’s worth noting that both Richard Hipp (SQLite) and Antirez (redis) are (or were) very deeply involved with Tcl. I think there maybe a positive feedback loop/environment wrt engineering discipline. It’s worth exploring. I also second the praise below of John Ousterhout’s (inventor of Tcl/Tk) book “A Philosophy of Software Design”.
- PCChris23 7y agoWhat do you like about Laravel and dislike about React? I like the Linux kernel codebase: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
- lossolo 7y ago> I like the Linux kernel codebase Same here, I was looking at linux kernel network code lately and I was surprised by how clean and easy to follow it was.
- 0mbre 7y agoAt some point in Martins book, he mentioned a forgotten codebase from one of his friend that was solely composed of tiny functions but yet achieve a fairly complex effect. That's the kind of feeling I had working at Laravel (admittedly it's been a few years). React codebase, on the other hand, seem less human-friendly, it seems to require some prior knowledge of the code to be able to dive into.
- ngngngng 7y agohttps://github.com/golang/go https://github.com/golang/go
- GoMonad 7y agoAnything by John Carmack. (DOOM's open source release, for example)
- dongecko 7y agoI'd second that. Some years ago I had a look at the quake 3 bots code, which I think were also written by John Carmack. The code was amazingly intuitive.
- chimpburger 7y agoThe Q3 bot AI was written by this man https://doomwiki.org/wiki/J.M.P_van_Waveren_(MrElusive) https://doomwiki.org/wiki/J.M.P_van_Waveren_(MrElusive) Carmack said that he was "the best developer I ever worked with"
- norswap 7y agoBecause of ego, I'm going to plug my own (a Java parsing tool): https://github.com/norswap/autumn4 https://github.com/norswap/autumn4 And hopefully I can some constructive criticism :) For something not from me but still in Java, the Proguard source code is very clean: https://sourceforge.net/p/proguard/code/ci/default/tree/ https://sourceforge.net/p/proguard/code/ci/default/tree/
- cunac 7y agoit reads like C , not like regular java all idioms are C like
- hartator 7y agoI think the best codebases are the ones you immediately think “Oh, that’s easy. I can reimplement that in a couple of hours.”. When it's not. It’s never easy.
- hugofirth 7y agoFor a C codebase, Postgres[1] wins for me hands down. It's clean and suuuuuuper well commente, such that with a little context you can dive into something very complex and still get a feel for what is going on. [1]: https://github.com/postgres/postgres https://github.com/postgres/postgres
- jakewins 7y agoSecond this; Postgres codebase is what got me out of the "good code is self documenting" nonsense. For those of us in the database space it is an incredible resource - and overall a great example of good code. sqlite is much less complex, but similarly approachable. In more recent examples, I think you see a lot of this same reader-centric pragmatic ethos in many Go projects. The Kubernetes codebase comes to mind as a very large tome that remains approachable. And the Go stdlib, of course. Java generally falls on the opposite side, but there are counterexamples. A lot of Martin Thompsons code eschews Java "best practices" in favor of good code. Seeing competent people in the Java space "break the rules" helps.. though of course Java is forever hampered by having internalized illegible patterns as best practices in the first place. It's a shame because at least the OpenJDK implementation of the standard library in Java is generally quite good, especially around the concurrency parts. Clean, easy to follow, reasonable comments. But of course that's Java written by C developers, mostly.
- h0bzii 7y ago/* don't even try to load if not enabled */ if (!jit_enabled) return false; I still think comments like these are super redundant and annoying.
- amboo7 7y agoAgreed, sounds like trying to convince that imperative code is an easy reading. But OK, for some people it may be.
- Someone1234 7y agoIt tells you the intent. The actual code does exactly that, because the intent matches the code, but sometimes the two aren't aligned and therefore the "redundant" comment can help you determine if the bug is the code or the intent. Understanding the "Why?" of code is often the most valuable thing about comments. The code remains forever, but the "Why?" is often lost to time.
- bijection 7y agoThe Codemirror codebase [0] is simply written and richly commented, and using Codemirror itself in a project is a pleasure. Tellingly, Marijn Haverbeke, Codemirror's creator, is also the author of the excellent 'Eloquent Javascript' [1]. [0] https://github.com/codemirror/codemirror https://github.com/codemirror/codemirror [1] http://eloquentjavascript.net/ http://eloquentjavascript.net/
- lol768 7y agoIt's unfortunate that the author doesn't appear to understand the value of a strict Content-Security-Policy.
- lol768 7y agoFor context, see this GitHub issue: https://github.com/codemirror/CodeMirror/issues/4937 https://github.com/codemirror/CodeMirror/issues/4937 Author is unwilling to change a handful lines of code to make the package compatible with a strict style-src. Why does this matter? You can exfiltrate data such as CSRF tokens using inline styles from a HTML injection vulnerability: https://medium.com/bugbountywriteup/exfiltration-via-css-injection-4e999f63097d https://medium.com/bugbountywriteup/exfiltration-via-css-inj...
- dajohnson89 7y agoSomeone mentioned joda-time. Does anyone know of other exemplary java repos?
- freetobesmart 7y agomany mature frameworks have good standards. For php you can look at any code base that adbides by PSR standards and get good code. Not only that but laravel is in a mature space where the problems are already solved. Its basically reinventing the wheel. Im not surprised that Laravel is written cleanly but I hate its API. It reminds me of the bloat of Zend but with an obnoxious artsy style added to it. Im an engineer not an artisan.
- noir_lord 7y ago> Im an engineer not an artisan. That was mostly branding, "I'm not a code monkey banging out the same thing as has been done 500 times before I'm an artisan. Meanwhile the actual framework breaks backwards compatibility regularly and frequently and only just with 6 picked a damn versioning system. Imo my opinion if you want to see a good framework that solves it's problems mostly well and is properly decoupled then Symfony kicks the shit out of Laravel on documentation, religious adherence to deprecating and backwards compatibility as well as genuinely useful/genuinely decoupled components. The author of Laravel knew that as a massive chunk of Laravel depends on Symfony components, in fact the earlier versions where basically Ruby on Rails implemented via Symfony.
- SahAssar 7y ago> look at any code base that adbides by PSR standards and get good code. No. PSR does not at all ensure good code, only standardized code style and some of the interfaces.
- cutler 7y agoPSR is an abomination. You end-up with more blank lines than code and about 5 lines of doc comments to every line of code. Factor-in PHP's pseudo-Java verbosity and the actual business logic is drowning in a sea of boilerplate.
- johannes1234321 7y agoIt does one thing: It indicates the author is willing to use "established patterns" instead of reinventing the wheel. (While sometimes it's good to reinvent the wheel - today's vehicles won't work with wodden wheels)
- myth_buster 7y agoKubernetes for Golang. This has been brought up as an example of fine documentation: https://github.com/kubernetes/kubernetes/blob/ec2e767e59395376fa191d7c56a74f53936b7653/pkg/controller/volume/persistentvolume/pv_controller.go#L54 https://github.com/kubernetes/kubernetes/blob/ec2e767e593953... Requests for Python https://github.com/psf/requests https://github.com/psf/requests
- snazz 7y agoI’m not sure I’d call Space Shuttle Style appropriate for 99% of code, but it does make it easy to read and harder to mess up down the road.
- sterlind 7y agoSpace Shuttle Style is appropriate when the design is fixed, the code is extremely tricky and it's very difficult to test - in other words, when it's not possible to follow normal good coding practices. If you can comprehensively test, then the docs can live there, and you don't need quite so many warnings about introducing bugs.
- otterley 7y agoK8S was transpiled from Java, and it shows. Much of the code isn't idiomatic Go at all. So I wouldn't cite K8S as a shining example. Comments like the one cited are fantastic, but we're interested in examplars of good (i.e., elegant and readable) code, not ancillary matter.
- luminati 7y agoVery interesting! I never knew that! Did a bit of googling to verify it. [1] [1] https://fosdem.org/2019/schedule/event/kubernetesclusterfuck/ https://fosdem.org/2019/schedule/event/kubernetesclusterfuck...
- vecplane 7y agoI've always been impressed by the quality of Three.js - https://github.com/mrdoob/three.js/ https://github.com/mrdoob/three.js/
- wvlia5 7y agoThe compiler for the B language, by Arthur Withney http://kparc.com/b/ http://kparc.com/b/
- chadcmulligan 7y agoha ha
- avmich 7y agoI'd add to this family the J system, ver. 7 - https://github.com/jsoftware/jsource https://github.com/jsoftware/jsource . A good example of creating a DSL and then efficiently using that. "Never had a memory leak from day 1 (Roger Hui)" (written in C).
- elijahlrc 7y agoUnreal 4 is far from perfect but considering the size of the project I would say its pretty impressive.
- sea6ear 7y agoI really liked the Go standard library (or at least from around 1.4-ish, it might have gotten more complicated now). I liked that it was actually possible to read it and understand what was going on. In a similar vein, P. J. Plauger's version of the The Standard C Library is nice because even if it might not be especially optimized(?), you can actually read the code and understand the concepts that the standard library is based on. Software Tools by Kernighan and Plauger would also be great except that you have to translate from the RatFor dialect of Fortran or Pascal to use the code examples. Even so, I used its implementation of Ed, to create a partial clone in PowerShell that let me do remote file editing on Windows via Powershell when that was the only access that was available. So even over 4 decades and various operating systems removed, there are still concepts in there that are useful. Jonesforth is also a great and mind blowing code base although I'm not sure where the canonical repository is currently.
- rwmj 7y agoI supposed it's this one, but it's public domain and over the years has been forked many many times (far more than I ever expected). http://git.annexia.org/?p=jonesforth.git;a=summary http://git.annexia.org/?p=jonesforth.git;a=summary
- agentultra 7y agoI think Brogue is quite nice to work with and well structured: https://github.com/tsadok/brogue https://github.com/tsadok/brogue Kudos also to Postgres, SQLite, Lean (theorem prover), and the containers library for Haskell.
- omarhaneef 7y agoI wish there was a way to read the codebase where there is a tag that tells you what the folder does. In github, rather than see what has changed, it would be interesting if there was a comment that told you what the folder contained. edit: Relevant here because the best codebase for me is one where I can understand the folder structure, but that is a sort of 0th order effect that should be equalized with some tool.
- mcculley 7y agoJava did this with package-info.java. It is underused, in my experience.
- PhilippGille 7y agoIn Go, a folder is a package and as soon as you write a comment before the `package foo` declaration, it's package documentation. And thus GoDoc automatically generates a nice webpage out of it. See for example this package comment: https://github.com/golang/go/blob/master/src/net/http/doc.go#L6-L104 https://github.com/golang/go/blob/master/src/net/http/doc.go... Turns into this documentation (the beginning only): https://godoc.org/net/http https://godoc.org/net/http Out of the box.
- omarhaneef 7y agoNice. I like the way it also shows you the functions inside a file/folder, and that clickable index is nice.
- heyoni 7y agoWhat's the point of all these empty comments throughout the code? // ...
- hazz99 7y agoIt's likely the Go libter requiring every public method / variable to be documented.
- n0n0n4t0r 7y agoWell, Symfony's codebase is really great: It is very readable, It's behavior is logical, The documentation is great, It uses common patterns (solid), so you are never loss
- bitwize 7y agoNetBSD, hands down. Beautiful, simple to understand, consistent. The documentation is also top notch -- I wrote a trivial character-device kernel driver using only the man pages as a reference. And you can too. Also -- the source code to Doom. Read it, marvel at its clarity and efficiency -- and then laugh when you realize that the recent console ports were completely rewritten in fucking Unity. And the Switch version chugs, despite the original running well on 486-class hardware.
- ashafer 7y agoI completely agree. I've gotten to work with both of these at my summer job and it's been an absolute pleasure.
- tomsmeding 7y agoYou've gotten to work with both NetBSD and Doom in one summer job? Now I'm really curious what you've been doing. I think I may want that too.
- deleted 7y ago[deleted]
- bitwize 7y agoThink about it. When you stand up a new ARM-processor embedded widget for the first time, what are two of the first things you do to verify it works? 1) Port NetBSD to it 2) Port Doom to it
- ashafer 7y agoMy project was to port DOOM to the seL4 microkernel (on rpi3b+). To continue with that I’ve been porting NetBSD Rump kernel components to seL4 as well. DOOM itself is a breeze to port. NetBSD can get confusing at times but it’s nice to know there’s always a logical reason behind the design decisions. It rewards you for spending time to understand the code and I like that. Rump kernels are especially cool. It’s a myth that you can’t get paid to work on BSD ;)
- 7y ago
- miguendes 7y agoJava: joda-time C: redis Python: scikit-learn _______ Edit: formatting
- jihadjihad 7y agoFor canonical C code, without a doubt I would say Redis and Postgres. Redis is written and annotated in a way that even someone with a cursory knowledge of C can understand what's going on. For Python, I really like how SQLAlchemy is written and designed. For Rust, ripgrep stands out as a sterling example of how to write a powerful low-level utility like that.
- massimo-nazaria 7y ago> Redis is written and annotated in a way that even someone with a cursory knowledge of C can understand what's going on. Strongly agree with this one about Redis.
- dataflow 7y agoI just opened up server.c in Redis (not familiar with Redis and never seen it before) and at first glance it seems... alright, but I'm not sure what's particularly outstanding about it, and it could definitely be better. Some of the logic seems questionable (exit() in a signal handler? [9] also what about thread safety?), and more superficially (but annoyingly) I see: names like "sdscatprintf" [1] which are a little cryptic, lack of attention to spacing (too little [2] or too much [3] or inconsistent [4] [8]), lack of braces for single-line blocks (which at least I consider bad) [5], irritatingly inconsistent line breaks [6], etc. Overall it's still definitely on the more readable side compared to other C code I've seen, I like the thorough comments, and it's generally decent, but I'm not particularly coming away from it in awe like everyone else seems to have. [1] https://github.com/antirez/redis/blob/unstable/src/server.c#L4184 https://github.com/antirez/redis/blob/unstable/src/server.c#... [2] https://github.com/antirez/redis/blob/unstable/src/server.c#L4499 https://github.com/antirez/redis/blob/unstable/src/server.c#... [3] https://github.com/antirez/redis/blob/unstable/src/server.c#L4217 https://github.com/antirez/redis/blob/unstable/src/server.c#... [4] https://github.com/antirez/redis/blob/unstable/src/server.c#L4505 https://github.com/antirez/redis/blob/unstable/src/server.c#... [5] https://github.com/antirez/redis/blob/unstable/src/server.c#L4421 https://github.com/antirez/redis/blob/unstable/src/server.c#... [6] https://github.com/antirez/redis/blob/unstable/src/server.c#L1839 https://github.com/antirez/redis/blob/unstable/src/server.c#... [7] https://github.com/antirez/redis/blob/unstable/src/server.c#L1783 https://github.com/antirez/redis/blob/unstable/src/server.c#... [8] https://github.com/antirez/redis/blob/unstable/src/server.c#L4384 https://github.com/antirez/redis/blob/unstable/src/server.c#... [9] https://github.com/antirez/redis/blob/unstable/src/server.c#L4535 https://github.com/antirez/redis/blob/unstable/src/server.c#...
- ekidd 7y agoAnything by burntsushi, but especially xsv and ripgrep: xsv: https://github.com/BurntSushi/xsv https://github.com/BurntSushi/xsv ripgrep: https://github.com/BurntSushi/ripgrep https://github.com/BurntSushi/ripgrep His code typically has extensive tests, helpful comments, and logical structure. It was fun trying to imitate his style when writing a PR for xsv. The Quake 2 engine was also pretty interesting: It was almost totally undocumented, and it had plenty of weird things going on. But I could count on the weird things being there for a reason, if only I thought about it long enough.
- mehrdadn 7y agoNote: this assumes you speak Rust...
- CDSlice 7y agoDon't all the comments assume you speak the language the codebase is written in? I mean I can't tell if a given PHP/C/Perl/other language I don't know well codebase is good or not. I guess there could be people that can somehow do that...
- mehrdadn 7y agoYes, but other comments actually mention the language, and the original post was using web languages as an example, so I thought I'd save someone the trouble of clicking expecting and realizing it's not what they expected.
- nindalf 7y agoSeconding burntsushi. I learnt the basic Rust idioms by doing the advent of code last year and comparing my solution to his.
- jamierumbelow 7y agoFor something a little different, the Clojure codebase – particularly `clojure.core` – is extraordinary in its elegance and simplicity.
- rch 7y agoI think Faust looks like exemplary modern Python. https://github.com/robinhood/faust https://github.com/robinhood/faust Also voted for Postgres, Redis, and NetBSD.
- th0ma5 7y agoMaybe I have a low-ish bar, but the Kodi Add-Ons in the official code base is a nice system of continuous integration with established acceptance and review procedures. I wrote a small add-on for a woodworking show and as soon as all the checks were passed and there was a final sign off, it was immediately available for installation on all platforms.
- dfan 7y agoThe Stockfish chess engine [1] is very nice, especially so since chess engines tend to be very kludgy. [1] https://github.com/official-stockfish/Stockfish https://github.com/official-stockfish/Stockfish
- projectileboy 7y agoarc.arc, core of the Arc language. Lots of lessons in there on how to write good Lisp code. I’d say the same thing about the core.clj of Clojure.
- jacquesc 7y agoMy personal favorite is Sequel. https://github.com/jeremyevans/sequel https://github.com/jeremyevans/sequel Beautiful codebase, rock solid, and way better option than ActiveRecord IMHO
- oogway8020 7y agoNot only it is a high quality codebase, support from Jeremy is a top notch, there are no outstanding issues, everything gets fixed promptly. It's been a great joy using both sequel and roda all these years
- lloeki 7y agominitest. The testimonials speak volumes. https://github.com/seattlerb/minitest https://github.com/seattlerb/minitest Apparently, some people think my toy channel implementation called Normandy is somehow good: https://github.com/lloeki/normandy https://github.com/lloeki/normandy
- tschwimmer 7y agoPerhaps I'm jaded, but I notice that all the examples given here are developer tools or otherwise things with well scoped functional inputs and outputs (e.g. ffmpeg). Anyone have an example of a consumer application that has a good codebase? Chromium, GitLab, OpenOffice, etc? I feel like such applications inherently have more spaghetti because the human problems they're aiming to solve are less concretly scoped. Even something as simple as "Take the data from this form and send it to the project manager" ends up being insanely complex and nitpicky. In what format should the data be sent? How do we know who the project manager is? Via what format should the data be sent? How should we notify the project manager? When should we send the report? Some of these decisions are inherently inelegant, so I feel like you get inelegant code.
- aidos 7y agoI actually find Chromium to be a lot more approachable than I assumed it would be. Have only really checked out the layout / graphics part of Blink, but it’s laid out pretty intuitively. But yeah, Postgres also gets my vote. I guess there’s a bit of a bias there because devs are likely to read the code of the tools they use; either to track downs bug or just to understand how it works.
- inlined 7y agoYeah. I was amazed to find out it was designed so flexibly to inject C++ backed JS objects (eg write a request function which added requests to a queue after certain lengths based on multi-tenant fairness). Clients couldn’t circumvent because system code wasn’t necessarily in JS user space.
- westoncb 7y agoIt seems like that's how this question is always answered. I'd also be interested to see some good application code. Also curious about some good, not too hugely sized, game code (preferably something not written in C/C++, maybe like an indie game from the past decade or so). Anyone know something?
- 7y ago
- SkyMarshal 7y agoPeter Norvig's sudoku solver (Python) is excellent. Solves every possible variant of sudoku. https://norvig.com/sudoku.html https://norvig.com/sudoku.html
- nXqd 7y agooh yeah, this one is so good. And his spell checker is really understandable, readable too https://norvig.com/spell-correct.html https://norvig.com/spell-correct.html
- kostarelo 7y agoI've been enjoying reading Spectrum's codebase[0]. It's very simple, with little documentation you can understand pretty much what is going on and in the architecture level, is as simple as it needs. The first time I tried to open a PR, I was up and running my feature in a few minutes. Small summary of the features I liked: - Simple documentation - Intuitive structure - Lots of JS best practices, but still simple - Event-driven architecture - A simple API gateway that will just fire events to workers - Properly divided workers (kind of microservices but with lots of shared code) - Monorepo It recently been bought by GitHub(1) and was discussed here(2). The author has talked in his blog about some decisions he took wrong. Super interesting post(2). 0. https://github.com/withspectrum/spectrum https://github.com/withspectrum/spectrum 1.https://spectrum.chat/spectrum/general/spectrum-is-joining-github~1d3eb8ee-4c99-46c0-8daf-ca35a96be6ce https://spectrum.chat/spectrum/general/spectrum-is-joining-g... 2. https://news.ycombinator.com/item?id=18570598 https://news.ycombinator.com/item?id=18570598 3. https://mxstbr.com/thoughts/tech-choice-regrets-at-spectrum/ https://mxstbr.com/thoughts/tech-choice-regrets-at-spectrum/
- carapace 7y agoIt's a toy, but I remember being very impressed with the implementation of Turing Drawings: http://maximecb.github.io/Turing-Drawings/ http://maximecb.github.io/Turing-Drawings/ https://github.com/maximecb/Turing-Drawings https://github.com/maximecb/Turing-Drawings
- jatsek 7y agoI’m only learning Swift and iOS dev but a fair amount of people recommended me to take a deeper look into Kickstarter for iOS app: https://github.com/kickstarter/ios-oss https://github.com/kickstarter/ios-oss
- sixstringtheory 7y agoCame here to post this. It's got some interesting usage of custom Swift operators to create almost diagrammatic code, like here: https://github.com/kickstarter/ios-oss/blob/master/Kickstarter-iOS/Views/Controllers/AddNewCardViewController.swift#L112-L115 https://github.com/kickstarter/ios-oss/blob/master/Kickstart... _ = self.cardholderNameTextField |> formFieldStyle |> cardholderNameTextFieldStyle |> \.accessibilityLabel .~ self.cardholderNameLabel.text And it's the first iOS codebase I've seen that puts test files right next to the files that define the things being tested. It's all there together. Tons of other goodies to find.
- akaralar 7y ago2 of the guys that worked on that app are doing video series about functional programming now where they talk a lot about the ideas in the app, https://www.pointfree.co https://www.pointfree.co
- sixstringtheory 7y agoNice rec! They're the ones that wrote the tagged [0] repo I use, had no idea they were connected. Very cool. [0]: https://github.com/pointfreeco/swift-tagged https://github.com/pointfreeco/swift-tagged
- ixtli 7y agoWeirdly I find the v8 source and jQuery (at least several years ago) to be the best. They're examples of real-world, multi-distributed-collaborator, mature projects. Harder, I think, than writing "clean" code is maintaining a large code base's organization, distribution, etc and these are really good examples of that. (d3 and three.js are also very interesting to read, but they're not quite in the same class as the former.)
- emmanueloga_ 7y agoSedgewick and Wayne algorithm implementations. Although, those are literally textbook implementations :-) I’m not quite sure what it would take to turn them into a production ready standard library (generics?), but they look like a good foundation for that purpose. https://algs4.cs.princeton.edu/code/ https://algs4.cs.princeton.edu/code/
- wrmsr 7y agoprestodb is the best java codebase I've ever worked in, llvm is the best c++ codebase I've ever worked in.
- thrownaway954 7y agoAnything by Tobias Lütke ( https://github.com/tobi https://github.com/tobi )
- SMFloris 7y agoOctave is amazingly written, in my opinion. I remember delving into its source expecting a mess made by mathematicians and instead found a very well organised and clean code base. Kudos to that team!
- pwpwp 7y agoMacPaint and QuickDraw Source Code https://www.computerhistory.org/atchm/macpaint-and-quickdraw-source-code/ https://www.computerhistory.org/atchm/macpaint-and-quickdraw...
- cbzehner 7y agoAlthough it's not a "codebase" per se, Architecture of OpenSource Applications is a great way to see how lots of major applications are structured. http://aosabook.org/en/index.html http://aosabook.org/en/index.html
- whalesalad 7y agoWhatever you do ... do not read the guts of PonyORM (python db orm). Also I would strongly urge anyone who has ever considered it to run, not walk, in the opposite direction.
- deleted 7y ago[deleted]
- rsweeney21 7y agoThe Windows operating system. Windows is quite an engineering achievement. We didn't prioritize readability or "clean code". All the variables used hungarian notation, so you had horrible names like lpszFileName (lpsz = long pointer to a zero terminated string) or hwndSaveButton (window handle). You also had super long if(SUCCEEDED(hr)) chains that looked like your code was spilling down a staircase. Oh yeah, and pidls (pronounced "piddles" and short for "pointer to an id list") used for file operations. What made the code base beautiful was the extreme lengths we went to to be fast and keep 3rd party software working. WndProcs seem clunky, but they are elegant in their own way and blazingly fast. All throughout the code base you would find stuff like "If application = Corel Draw, don't actually free the memory for this window handle because Corel uses it after sending a WM_DESTROY message." The fact that thousands of people worked on the code base was mind boggling.
- cryptica 7y agoThe Windows API was very ugly... not to mention unnecessarily complicated. It does not belong in this thread.
- holy_city 7y agoPersonally, COM gives me the heebie-jeebies. I get why it exists and think it's a cool idea. Under the hood it's just RTTI across shared library boundaries, and it's cool that it "just works" with the way that compilers generate vtables from pure virtual base classes. But hell did it take me awhile to figure out how that worked because it's so poorly documented and auto-magical. Reverse engineering a COM DLL just to find out how the hell it has a stable ABI is not fun.
- inlined 7y agoAlso the whole point of COM was interface composition which led to the diamond problem (multiple inheritance) in any real C++ object that implemented two interfaces (which each had to inherit IUnknown if all implementations were to be COM compatible). Virtual inheritance was a hack fix to a platform whose primary language fought its primary purpose.
- ts4z 7y agoIn 2010, the nginx source was quite startling. It's very readable C, but also somewhat difficult in that it did not mechanize a lot of bookkeeping. If it wanted to construct a string of 8 components, there were 8 components in getting the length right, then 8 adds to the string. This was toil, and error-prone. But it was always done with such precision, and so consistent, that it was still quite beautiful.
- vbezhenar 7y agoWhenever I have to dig into Spring sources, they always look awesome. This is the best Java project I've ever seen. Clean concise code, versatile architecture using proper design patterns, lots of documentation.
- c-smile 7y agoI was impressed by code of Konstantin Knzhnik ( http://www.garret.ru/ http://www.garret.ru/ ). All his database engines in particular.
- cryptica 7y agoUnfortunately, I've found that almost all developers are incapable of objectively judging the quality of code until they actually have to start working with it and then after a few months they can start to appreciate or despise the code. It takes a lot of investment from a developer before they can appreciate the beauty of the code... To make matters more confusing, a lot of developers tend to become extremely attached to even horrible code if they spend enough time working with it; it must be some kind of Stockholm syndrome. I think the problem is partly caused by a lack of diversity in experience; if a developer hasn't worked on enough different kinds of companies and projects, their understanding of coding is limited to a very narrow spectrum. They cannot judge if code is good or bad because they don't have clear values or philosophy to draw from to make such judgements. If you can't even separate what is important from what is not important, then you are not qualified to judge code quality. If you think that the quality of a project is determined mostly by the use of static vs dynamic types, the kind of programming paradigm (e.g. FP vs OOP), the amount of unit test coverage and code linting, then you are not qualified to judge code quality. I think that the best metric for code/project quality is simply how much time and effort it takes for a newcomer to be able to start making quality contributions to the project. This metric also tends to correlate with robustness/reliability of the code and also test quality (e.g. the tests make sense and they help newcomers to quickly adapt to the project). As developers, we are familiar with very few projects. If a developer says that they like React or VueJS or Angular, etc... they usually have such limited view of the whole ecosystem that their opinion is essentially worthless; and that's why no one ever seems to agree about anything. We are all constantly dumbing down everything to the lowest common denominator and regurgitating hype. Hype defies all reason. It's the same with developers; most developers (especially junior and mid-level) are incapable of telling who is actually a good developer until they've worked with them for about 6 months to a year. If you are not a good developer, you will not be able to accurately judge/rank someone who is better than you at coding until several months or years of working with them. Sometimes it can take several years after you've left the company to fully realize just how good they were.
- Confusion 7y agoIt’s like you’re reading my mind. This matches my experience closely and is exactly what I first thought of when I saw this topic.
- oaxacaoaxaca 7y agoDjango! And django rest framework. To me, both codebases are so readable and so well put together that even if their documentation was bad (which it isn't), you could fully grasp their APIs and how to use their libraries by just reading through some of the code.
- pacofvf 7y agoI would add Flask too, I guess everyone on that realm of python learned the lesson from werkzeug, which after all these years some functions/classes still doesn't have docstrings and variable names are awful.
- kamyarg 7y agoSecond this; dove into Django and DRF source multiple times in the past, always got out with more than I wanted. Ofcourse on 95% of the occasions the docs are good enough.
- pandler 7y agoAlso agree! I learned a lot about how Python works from digging through the inner guts of the Django ORM. I’ve been pleasantly surprised, getting back into Django after about 5 years, that the codebase is just as comprehensible as I remember it to be, and the documentation equally as comprehensive.
- flavio81 7y agoThe easiest to read codebases I've found were all written in Common Lisp, like the clsql lib for example.
- quadcore 7y agoit seems that in real life, a really high-quality codebase is hard to come by I think a common misconception amongst mid-experienced programmers is that they confuse look with quality. Reading clean written code gives you a feeling of control and also the feeling that someone must have thought about that program. It's reassuring. You have in front of you a code that gives you trust. When in fact, that code can be complete garbage. The look of the code doesn't matter, what matters is the program. In the abstract meaning of the term. You don't judge a code by reading it, but by running it in your head. Granted you have to understand it in order to do that. Once you understand the code, you run it in your head and that's when quality enter the scene because running it in your head is what you do all day when you code. Some says that you spend most of your time reading code. That's simply not true, the effort is definitely not in reading but in running the code in your head. Basically what I'm describing is a 2 by 2 matrix where there is one column for look bad, one for look good, one row for runs badly in the head and one for run smoothly in the head. Granted, the best may be when both the code looks right and runs right, but don't be mistaken, the real important and difficult part is whether or not it runs well in the head. A poor quality program may look good, but don't run well in the head. It's too complex or too confusing (in terms of logic, not in terms of presentation) or convoluted or simply wrong in terms of what it's supposed to do. On the other hand good quality code is code that surprises you by the way it runs. It's beautiful in terms of simplicity, it delivers a lot, it's small so that it fits well in the coder's head. And it may look like garbage which is not so important. You may wonder how to know very quickly the quality of a code base. Run part of it in your head. Contemplate the machinery. Try not to think to much about the language and how it's constructed in this language, try instead to contemplate it in an abstract manner. Be critic, and critic your critics.
- Yajirobe 7y agodont u mean a 2x2 matrix
- Izkata 7y ago> by running it in your head. I have encountered far too many people who don't even realize this is a thing. I figure they must be doing it in some limited form and just aren't recognizing it as a skill that can be trained up, otherwise I'm not sure how they can do any development, but...
- typedef_struct 7y agoWith some healthy spoonfuls of caveats, Quake 3 (https://github.com/id-Software/Quake-III-Arena https://github.com/id-Software/Quake-III-Arena). Skipped a lot of classes back in the day ripping that one apart and piecing it back together again.
- canada_dry 7y agohttps://github.com/achael/eht-imaging https://github.com/achael/eht-imaging This python code is responsible for the fairly recent imaging of the black-hole (i.e. imaging, analysis, and simulation software for radio interferometry). It's extremely easy to digest despite the complexity involved.
- luminati 7y agoSee also [1] Interesting Codebases: https://news.ycombinator.com/item?id=15371597 https://news.ycombinator.com/item?id=15371597 [2] Show HN: Awesome-code-reading - A curated list of high-quality codebases to read https://news.ycombinator.com/item?id=18293159 https://news.ycombinator.com/item?id=18293159
- 0mbre 7y agoThanks for the links!
- spinlock 7y agoNot your question but I think the bash source code is the worst I've ever seen.
- chadcmulligan 7y agoThe Lua source code is very easy to read, especially for an interpreter. It's a hand written recursive descent parser and incredibly tiny. http://www.lua.org http://www.lua.org
- vimanuelt 7y agoPlan 9 codebase has been the best that I have encountered. http://9p.io/sources/plan9/sys/src/ http://9p.io/sources/plan9/sys/src/
- Congeec 7y agoTornado, a python web framework. I doubt it is still popular today. But reading the source code is a pleasure. Its naming conveys clearly; its encapsulation allows extensibility; its documentation teaches me how to write an industry-level library. https://github.com/tornadoweb/tornado/blob/master/tornado/ioloop.py https://github.com/tornadoweb/tornado/blob/master/tornado/io...
- jbarham 7y agoI used Tornado to build the the WebSocket back end for this page: https://www.slickdns.com/live/ https://www.slickdns.com/live/. It's less than 100 lines of code and very clean. For most web apps my default choice is Django, but for special purpose web servers Tornado or Flask are still useful.
- ahmedfromtunis 7y agoI enjoy reading Django's source code so much. I also love writing Django apps. Its elegance forces me to write a much cleaner code.
- the_arun 7y agoFor Java, below are my favorites: 1. Jersey - https://github.com/eclipse-ee4j/jersey https://github.com/eclipse-ee4j/jersey 2. Jetty - https://github.com/eclipse/jetty.project https://github.com/eclipse/jetty.project 3. Guava - https://github.com/google/guava https://github.com/google/guava Common theme is - Easy to follow, clean documentation & use of consistent patterns.
- effnorwood 7y agoSolaris
- musicale 7y agoFor C, I thought Tcl had code that was easy to read and understand.
- m463 7y agosel4 microkernel is pretty cool. "The world's first operating-system kernel with an end-to-end proof of implementation correctness and security enforcement is available as open source." for instance, look at strnlen: word_t strnlen(const char *s, word_t maxlen) { word_t len; for (len = 0; len < maxlen && s[len]; len++); return len; } http://sel4.systems/ http://sel4.systems/ https://github.com/seL4/seL4 https://github.com/seL4/seL4
- alexanderscott 7y agoI found the Akka source code to be very clean and readable: https://github.com/akka/akka https://github.com/akka/akka
- manifoldQAQ 7y agoZeroMQ[1] for sure. It has a clean interface wrapped over low-level IO details and a well-designed unified polling mechanism. It's a piece of art. [1] https://github.com/zeromq/libzmq https://github.com/zeromq/libzmq
- flukus 7y agoSuckless tools (https://suckless.org/ https://suckless.org/), clean, efficient, small (easy to know the whole codebase) and very hackable, hackable to the point where even configuration is in code: https://git.suckless.org/dwm/file/config.def.h.html https://git.suckless.org/dwm/file/config.def.h.html
- Sir_Cmpwn 7y agoI would especially recommend reading through sbase and ubase: https://git.suckless.org/sbase/ https://git.suckless.org/sbase/ https://git.suckless.org/ubase/ https://git.suckless.org/ubase/
- deleted 7y ago[deleted]
- farah7 7y agoI would say the Mattermost ("open Source slack") codebase: Go server: https://github.com/mattermost/mattermost-server https://github.com/mattermost/mattermost-server React frontend app: https://github.com/mattermost/mattermost-webapp https://github.com/mattermost/mattermost-webapp
- sidcool 7y agoAny good to study Kotlin codebases? Or even Java (8+)?
- sidcool 7y agoA side question. What is a good way to start understanding such code bases as mentioned on here, so that the learning is optimal and effective?
- inlined 7y agoI liked some Objective-C codebases that adhered to the muffin-man principle: - (BOOL) doYouKnowTheMuffinMan:(TheMuffinMan *)theMuffinMan; Also, lots of the Objective-C runtime code was clear enough to explain concepts like ARC hacks well enough that I could learn about and give a talk on the Objective-C runtime with a month’s notice.
- vs4vijay 7y agoWell there was a post few year back with title "Best-architected open-source business applications worth studying?" : https://news.ycombinator.com/item?id=14836013 https://news.ycombinator.com/item?id=14836013
- aamederen 7y agoI work at Citus (now Microsoft) so my opinion is biased but I think Citus [1] codebase is a really good example. It borrows all the best practices from PostgreSQL the naming of variables and functions are more self-explaining in general. I also believe that the practices around PRs and code reviews are also good examples. [1] https://github.com/citusdata/citus https://github.com/citusdata/citus
- artpar 7y agoHere are a couple of codebases https://medium.com/@012parth/what-source-code-is-worth-studying-8755f88f8de5 https://medium.com/@012parth/what-source-code-is-worth-study...
- enkiv2 7y agoThe cleanest real/nontrivial code I've seen is the plan9 implementation of the standard unix command line tools.
- heathenaspragus 7y agoI've had the pleasure of working on this: https://github.com/cloudify-cosmo https://github.com/cloudify-cosmo was the cleanest I've seen
- willfr 7y agoI really like AllenNLP. https://github.com/allenai/allennlp https://github.com/allenai/allennlp
- jMyles 7y agoI think that the Twisted codebase has the best combination of sound and comprehensive metaphor, straightforward functionality, and fun. I also enjoy diving into it when I hit a breakpoint that calls one of its methods.