

Ask HN: Particularly elegant programs to study? - sz

Examples help tremendously in learning any abstract subject.  What are some famously well-written programs whose source is available to look at?
======
variety
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
> 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
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...](http://conal.net/blog/posts/denotational-design-with-type-class-
morphisms/)

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

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

~~~
jamii
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/>

------
michael_dorfman
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
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
(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
sqlite is both beautiful and has a significant test suite.
<http://www.sqlite.org/>

~~~
jamii
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.

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

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

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

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

<http://www.lua.org/>

~~~
davidsiems
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.

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

------
techbio
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>

------
petercooper
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>

------
jbarham
<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.

------
doublez
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 ... ;)

~~~
doublez
<https://github.com/lift/lift>

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

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

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

