Ask HN: What source code is worth studying?
403 pointsThis is one my favourite questions, asked by idlewords: https://news.ycombinator.com/item?id=879101
But its been a long time since then, and with a new set of programming languages, I believe there are new code bases that's worth studying about and learning from.
So, which code-base should I be reading about to improve myself?
Comments (166) 76 threads
Show all comments
Showing thread 71 of 76
Just pick one and force yourself to use it to the exclusion of other editors. Future you will thank you later, because you'll still be using it 20 years from now. "We are typists first, programmers second" comes to mind. You need to be able to move chunks of code around, substitute things with regexes, use marks, use editor macros, etc.
== 6.824: Distributed Systems ==
http://pdos.csail.mit.edu/6.824-2013/ Do each lab. Read the discussion and rtm's course notes.
== Tarsnap ==
https://www.tarsnap.com/download.html How to write C. Study the "meta," that is, the choice of how the codebase is structured and the ruthless attention to detail. Pay attention to how functions are commented, both in the body of the function and in the prototypes. Use doxygen to help you navigate the codebase. Bonus: that'll teach you how to use doxygen to navigate a codebase.
== xv6 ==
http://pdos.csail.mit.edu/6.828/2012/xv6.html
http://pdos.csail.mit.edu/6.828/2012/xv6/xv6-rev7.pdf
http://pdos.csail.mit.edu/6.828/2012/xv6/book-rev7.pdf
Read the book. Force yourself to read it in its entirety. Use the source code PDF to study how to turn theory into practice.
== Arc ==
http://ycombinator.com/arc/arc3.1.tar
You're not studying Arc to learn Arc. You're studying Arc to learn how to implement Arc. You'll learn the power of anaphoric macros. You'll learn the innards of Racket.
Questions to ask yourself: Why did Racket as a platform make it easier to implement Arc than, say, C/Golang/Ruby/Python? Now pick one of those and ask yourself: what would be required in order to implement Arc on that platform? For example, if you say "C," a partial answer would be "I'd have to write my own garbage collector," whereas for Golang or Lua that wouldn't be the case.
The enlightenment experience you want out of this self-study is realizing that it's very difficult to express the ideas embodied in the Arc codebase any more succinctly without sacrificing its power and flexibility.
Now implement the four 6.824 labs in Arc. No, I'm not kidding. I've done it. It won't take you very long at this point. You'll need to read the RPC section of Golang's standard library and understand how it works, then port those ideas to Arc. Don't worry about making it nice; just make it work. Port the lab's unit tests to Arc, then ensure your Arc version passes those tests. The performance is actually not too bad: the Arc version runs only a few times slower than the Golang version if I remember correctly.
== Matasano crypto challenges ==
http://www.matasano.com/articles/crypto-challenges/ Just trust me on this one. They're cool and fun and funny. If you've ever wanted to figure out how to steal encrypted song lyrics from the 70's, look no further.
== Misc ==
(This isn't programming, just useful or interesting.)
Statistics Done Wrong http://www.statisticsdonewrong.com/
A Mathematician's Apology http://www.math.ualberta.ca/mss/misc/A%20Mathematician's%20A...
Surely You're Joking, Mr. Feynman http://web.archive.org/web/20050830091901/http://www.gorgora...
Zen and the Art of Motorcycle Maintenance http://www.arvindguptatoys.com/arvindgupta/zen-motorcycle.pd...
== Above All ==
Don't fall in love with studying theory. Practice. Do what you want; do what interests you. Find new things that interest you. Push yourself. Do not identify yourself as "an X programmer," or as anything else. Don't get caught up in debates about what's better; instead explore what's possible.
> There are at last count something like twelve thousand people who have reached out to us for our free crypto challenges [...] Every damn one of those people is an email exchange that me, Sean, or Marcin had to have directly, on our own time, with no compensation.
I imagine the response time can vary quite a bit.
It got better when I remembered we're a Matasano client so I shouldn't feel so guilty about harassing them. But it's an awesome free thing they're doing, so I still do feel a little guilty.
Yet every single programming job post these days is basically looking for someone with X years of experience in a long enumeration of specific technologies. The usual reason being "They need to be productive. Now."
Any place worth working isn't looking for the absolute best candidate for X at any cost. A good fit with someone with a good work ethic who wants to learn always works out better than just raw expertise. And a reference from someone you both respect is the fastest most reliable place to find them.
Continue this thread — 3 replies
How to read the discussions? I think it's not publicly available. Btw, thanks a lot for the great post.
Continue this thread — 2 replies
> How to write C. Study the "meta," that is, the choice of how the
> codebase is structured and the ruthless attention to detail. Pay
> attention to how functions are commented, both in the body of the
> function and in the prototypes.
I just had another look at the tarsnap source code, and while I know Percival is a great guy, and I can't imagine him suing over "mis-use", the bulk of the code is under a pretty restrictive lisence:
"Redistribution and use in source and binary forms, without modification, is permitted for the sole purpose of using the "tarsnap" backup service provided by Colin Percival."
That is, except the code under "libcperciva" which appears to be under a traditional 2-clause BSD license.
So, for example using the bsdtar.c file to teach yourself how to handle command line arguments might be a bit dicey, as it's entirely unclear which part of that file is under the BSD license, and which part you're not allowed to distribute.
It's one of the reasons why I'd which Percival made the entire thing available under a dual license (eg: BSD) and simply required people to use the official client for the tarsnap service.
Then again, I'm not used to audit closed source software, and therefore probably extra scared of what might happen if I accidentially learn something from reading said source... ;-)
On the other hand, Percival does publish quite a lot of stuff that's [ed: entirely free], such as spiped https://www.tarsnap.com/spiped.html .
Anyway, illegal is illegal, and copy-pasting from Tarsnap would be illegal. I didn't know Tarsnap was under a restrictive license. It's a shame that people will have to be so careful when learning from Tarsnap, as it's a paragon of modern C best practices, but maybe the license is shrewd.
Though I wish the mentality of "my competitors might steal the code!" will die its deserved death, since evidence thus far suggests it's just paranoia. For example, the codecombat guys open sourced everything and have been fine: https://news.ycombinator.com/item?id=7015126 (But of course that's easy for me to say when I have no competitors to worry about!)
Continue this thread — 3 replies
I took SICP a long time ago... all the pure functional stuff was great and elegant. I never really got how you can program "real world" / stateful stuff like distributed systems in Lisp dialects. When I look at Lisp code with hash tables and so forth it just looks horrible to me.
(Note: These html pages are rendered incorrectly on mobile. In particular, the spacing is wrong due to vimscreenshot not inserting instead of actual spaces. Sorry about that. Try viewing these links from a desktop computer instead.)
https://dl.dropboxusercontent.com/u/231528979/arc/html/index...
Lab 1 in Go:
client.go https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
server.go https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
tests https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
output https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
Lab 1 in Arc:
client.arc https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
server.arc https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
tests https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
output https://dl.dropboxusercontent.com/u/231528979/arc/html/locks...
Git commit log: https://dl.dropboxusercontent.com/u/231528979/arc/html/log.h...
All diffs between my local codebase and the stock arc 3.1: https://dl.dropboxusercontent.com/u/231528979/arc/html/all-d...
I was interested in seeing how much code can be eliminated by using Arc instead of Go. Turns out: quite a lot. The server is almost 200 lines of Go code, but about 65 of Arc. The client is almost 120 lines of Go, about 35 of Arc. The unit tests are pretty similar in length (~480 vs ~410) but the Arc version is easier for me to read since there's less visual noise.
Anyway it was fun.
OT question, what's up with programmers and "Zen and the Art of Motorcycle"? I usually finish all the books I start reading and this was one of the exceptions. After an idea saying something like "we can't define quality ergo everything is quality" or something of the sorts I had to put it down, nothing made any sense and it all seemed to be a grandiose philosophical scheme based on random half-baked ideas.
Oh well, I should spend less time on HN...
I see this a lot. Do people not realize that the language is called Go, and that 'golang' is just a domain name, like 'ruby-lang', 'scala-lang' etc?
Continue this thread — 1 more reply
Continue this thread — 2 more replies