You've probably seen calls for recommendations for good code to read and study. When this comes up on aggregators and stackoveflow, the result is pretty scattershot. Here is my own list, with only code I've read enough of to judge as in some way interesting.
Canonizing my personal recommendations is a little fraught, since I know some of the authors and potential authors. Don't take an omission as much of a signal; we all have finite time, biases, and different goals and tastes. I'd love to get suggestions, by pull request or otherwise.
Hopefully I'll add critical remarks, though I'm lazy.
(An exception to the my-own-judgement rule.)
- https://www.gigamonkeys.com/code-reading/
- https://www.hanselman.com/blog/CategoryView.aspx?category=Source+Code
- Code Reading: The Open Source Perspective https://www.spinellis.gr/codereading/
- Ask HN: What source code is worth studying? https://news.ycombinator.com/item?id=7602237
- Ask HN: Good python code for code reading https://news.ycombinator.com/item?id=327710
- https://python-guide.readthedocs.org/en/latest/writing/reading/
- https://c2.com/cgi/wiki?ProgramsToRead
- https://programmers.stackexchange.com/questions/38874/where-do-you-go-to-read-good-examples-of-source-code
- https://c2.com/cgi/wiki?TipsForReadingCode
- https://www.quora.com/Where-can-a-programming-beginner-go-to-read-good-code
- https://www.readingcodegood.com/
- https://www.sitepoint.com/reading-ruby-professional-development/
- https://lukego.github.io/blog/2012/10/24/readable-programs/
(I've contributed in small ways to several of these.)
- https://norvig.com/paip.html
- Java, Lisp and Python Essays at https://norvig.com/
- IPython notebooks https://norvig.com/ipython/
- "Design of computer programs" on Udacity https://www.udacity.com/course/design-of-computer-programs--cs212
- on CodingBat https://codingbat.com/home/[email protected]
- kragen-hacks has lots of interesting short programs.
It's hard to find good models of contracts and invariants driving and documenting code. This book with its examples taught me this.
So old-school it’s practically prehistoric, but the best book I know on the philosophy of Unix (with the possible exception of ESR’s The Art of Unix Programming, but that book has hardly any code, and thus is not so relevant to this question). The longest example is a small programming language with a compiler and VM interpreter developed in stages. https://cm.bell-labs.com/cm/cs/upe/
Develops variants of a bunch of classic Unix tools, back before Unix became popular. https://www.amazon.com/Software-Tools-Pascal-Brian-Kernighan/dp/0201103427
Many surprisingly interesting and compact examples. (E.g. a ‘make’ in half a page of code, an assembler and interpreter, a command-line database system, etc., etc., etc.) Code is available for download, but it’s best with the book, which is unfortunately ridiculously expensive these days. https://cm.bell-labs.com/cm/cs/awkbook/
Just what it says, with code in Haskell and ML. Not your parent’s data-structures book. https://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
Has a few extended examples doing neat things. https://www-cs-faculty.stanford.edu/~knuth/lp.html
Ideas from the functional-programming world brought to Perl. The longest example is a constraint-based domain-specific language for diagram drawing. https://hop.perl.plover.com/
An overlooked classic with lots of fun code in a terribly obsolete programming language. Emphasis on string processing. Hard to find. The code is available online but probably hard to get much benefit from without the book. https://www.amazon.com/dp/0471302139/
Fine examples of the power of Lisp. The best chapters on macros I’ve seen anywhere. His programming style is not so much to my taste (favoring too-abbreviated global names, anaphoric macros, etc.) but still interesting and educational.
https://www.paulgraham.com/onlisp.html
https://en.wikipedia.org/wiki/Practical_Common_Lisp
A bit of a grab-bag but a tasteful exposition of ideas and examples relevant to functional programming as well as Prolog. O'Keefe is entertainingly opinionated, not unlike Snape at Hogwarts when a student screws up. https://www.amazon.com/dp/0262150395/
A collection of articles, each an extended example, with code, of making Prolog do something interesting, usually something AI-ish. Chapters by O'Keefe, Chris Mellish, Sterling, others. https://www.amazon.com/dp/0262193019/
A full, portable, clean, reasonably efficient implementation of the (C89) standard library, with discussion of the design tradeoffs. Includes the relevant pages from the standard. https://www.amazon.com/dp/0131315099/
Lots of small but nontrivial examples of developing a program and its proof of correctness hand-in-hand. https://www.amazon.com/dp/013215871X/
I've read https://github.com/rswier/c4 but not https://github.com/rswier/swieros