top | item 1914737

Ask HN: Particularly elegant programs to study?

44 points| sz | 15 years ago | reply

Examples help tremendously in learning any abstract subject. What are some famously well-written programs whose source is available to look at?

24 comments

order
[+] variety|15 years ago|reply
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).

[+] kazuya|15 years ago|reply
> 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?

[+] jamii|15 years ago|reply
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.

[+] sz|15 years ago|reply
This looks awesome, thanks. How to design abstractions was what I had in mind when posing the question.
[+] michael_dorfman|15 years ago|reply
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.

[+] jashmenn|15 years ago|reply
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
[+] sz|15 years ago|reply
(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]

[+] d4rt|15 years ago|reply
sqlite is both beautiful and has a significant test suite. http://www.sqlite.org/
[+] jamii|15 years ago|reply
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.
[+] plinkplonk|15 years ago|reply
Code from Peter Norvig's "Paradigms of Artificial Intelligence Programming"
[+] nomurrcy|15 years ago|reply
Lua (The programming language) is very well written and well worth reading and understanding.

http://www.lua.org/

[+] davidsiems|15 years ago|reply
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.

[+] doublez|15 years ago|reply
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 ... ;)
[+] dawsdesign|15 years ago|reply
I've heard that Postfix is as close to perfect you can get, but I haven't dived in personally.
[+] pierrefar|15 years ago|reply
I've heard good things about the code of Redis and Tokyo Tyrant.
[+] abyssknight|15 years ago|reply
c99shell. No, really, it's very well written.