Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Particularly elegant programs to study?
44 points by sz on Nov 17, 2010 | hide | past | favorite | 24 comments
Examples help tremendously in learning any abstract subject. What are some famously well-written programs whose source is available to look at?


The djb way: "straight, no chaser":

   http://cr.yp.to/
qmail in particular, and also (if you like math) primegen.

BTW, his code is not easy to understand (quite the opposite) -- there are few source comments, and most of these are snarky, cryptic or both; and not only does he explain almost nothing on a global scale but oftentimes what he is doing might look, at first blush, kinda wrong, obtuse even.

But that's precisely the point -- there are a lot of idioms in there that most C programmers just wouldn't think of, especially if you're into minimalism (when it comes to things like dealing with strings, error handling, forking, etc).


> and not only does he explain almost nothing on a global scale but oftentimes what he is doing might look, at first blush, kinda wrong, obtuse even.

Can you give some examples?


I don't know about famous, but Conal Elliots ideas about denotational semantics have led to some beautifully elegant libraries - http://conal.net/blog/posts/denotational-design-with-type-cl...

Don't be put off by the academic tone, at its heart the paper is about how to design abstractions.


This looks awesome, thanks. How to design abstractions was what I had in mind when posing the question.


I really enjoy reading Conals work. This paper is a particularly good example of how denotational semantics can guide the design of a library - http://conal.net/blog/posts/paper-beautiful-differentiation/


Léon Bottou's implementation of Stochastic Gradient SVMs is the most concise implementation of an SVM that you'll find: http://leon.bottou.org/projects/sgd


(since I had to look it up what a SVM was)

"Support vector machines (SVMs) are a set of related supervised learning methods... The standard SVM takes a set of input data, and predicts, for each given input, which of two possible classes the input is a member of... Intuitively, an SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible. New examples are then mapped into that same space and predicted to belong to a category based on which side of the gap they fall on." [wikipedia]


sqlite is both beautiful and has a significant test suite. http://www.sqlite.org/


The sqlite test suite is a fantastic example of how to produce solid software. I wish it were used as a case study for all software engineering courses.


TeX.

Or, any of Knuth's other Literate Programs.

Also, the book "Beautiful Code" is an attempt along these lines, but personally, I don't find the programs there as beautiful as Knuth's.


Here's Peter Norvig's toy spelling corrector (in Python), along with some helpful explanation:

http://norvig.com/spell-correct.html


Code from Peter Norvig's "Paradigms of Artificial Intelligence Programming"


Lua (The programming language) is very well written and well worth reading and understanding.

http://www.lua.org/


I have to disagree. The language spec and the docs on the Lua website are well written but the VM itself is a mess. It's a trainwreck of ambiguously named variables, minimal documentation, and overuse of macros to force inline code.

The Lua VM is a good example of something that isn't well written from a reading / understanding point of view, but is something that is well written from the 'it works' point of view.


Here are the source code reading order recommendations by Mike Pall (the author of LuaJIT).

http://www.reddit.com/r/programming/comments/63hth/ask_reddi...


I am surprised that nobody has pointed to http://news.usethesource.com/ yet.


This is very Ruby specific (so mostly not "famous" stuff) but if that's your scene, I asked the same question to Rubyists recently and got some good suggestions: http://www.rubyflow.com/items/1817


I searched for "russian doll pseudocode" hoping to discover something elegant, but the clearest "code" there is a nicely colored Venn-ish diagram.

http://ijcai.org/papers09/Papers/IJCAI09-106.pdf


http://code.google.com/p/go/source/browse/ is the source for the Go compilers and standard library. Very clean, clear code in the Bell Labs tradition.


The Lift framework core has some rather lithe Scala in it. Do mind that it's an actively developed, actively deployed framework - functionality sometimes takes priority ... ;)



I've heard that Postfix is as close to perfect you can get, but I haven't dived in personally.


I've heard good things about the code of Redis and Tokyo Tyrant.


c99shell. No, really, it's very well written.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: