4 ms·
Reading code, is second to using it and working with it. Someone can tell you "This is good code." but good for what? Why is it good? It is fast code? Is it
by ilc 3y ago
Reading code, is second to using it and working with it.
Someone can tell you "This is good code." but good for what? Why is it good?
It is fast code? Is it highly maintainable? Is it well documented and kept up to date? Is it a code that is highly reliable? Is it code that solves and important problem?
My rule of thumb is: Ugly code usually comes from ugly problems. Ugly code can often be some of the most valuable code, because... it does the ugly things! It does what we want 99.9% of the time, using heuristics, and other nasty stuff.
So don't judge code on if it is "good" or not. Judge it on if it does what the author intended, and if it doesn't suck too badly to read with no reason.
Code bases I've worked in and have opinions on:
Samba: Good code base, but you MUST understand the idioms of the codebase, or it is absolutely horrible. It also alas, has the wisdom of 20+ years of existence in it... so it isn't always pretty.
Illumos/OpenSolaris: Nice codebase. Get the SmartOS distribution and you can literally type a few commands and build an entire OS and userland.
FreeBSD: See above. Great codebase, ans also, it can build userland + kernel, though it takes a few more commands. I'll admit I haven't read this one in 20 years. But I always found it a good codebase to work in back when :).
Grab the source for a library you use all the time, you know the useful one but the API feels a bit off... Download it and look at why the API is the way it is.
When looking at code, do NOT neglect looking at the history of a given file or piece of code, it often can teach you quite a bit. :)