Recently I’ve been making a conscious effort to start finding and reading more good-quality source code, in an effort to become a better programmer (I won’t come out and say I’m good, but it is OK to say you want to get better right). So far this has encompassed the ROTOR Source Code (I haven’t read all 3M LOC yet…), and the Mozilla browser source code (once again, only scratching the surface on this one). This week-end I skimmed through the source for the recently released IssueTracker ASP.NET starter kit. IssueTracker seems like a pretty cool sample app, it is nicely architected and the code base is very clean and minimalist.
I think it is a great shame that most programmers don’t read more high-quality code. This is purely anecdotal but I would imagine most programmers reading of other code falls into the following categories:
Reading Sample Code in the MSDN or in an article to learn how to do something.
Reading code other team members have written (development/maintenance on an existing code base)
A 20 line demo program designed to illustrate on thing as simply as possible is very different from an application tens or hundreds of thousands of lines long. Studying these to become a good programmer would be like trying to become a good writer by studying sayings from fortune cookies. Reading team-mates code may be a good idea, or not (depending on the quality of your team-mates). You may pick up a few tips and tricks, you might pick up some bad habits too. If the code base is older it may not represent the current recommended practices (I’ll use the word “recommended” here instead of “best” so you don’t have to drag me out into the street and shoot me). You may learn just as much about what NOT to do (but hey, these lessons are still just as valuable). If you’re doing some maintenance work on an existing code base then the focus may be more on making the required changes and getting back to something else rather than learning things.
A book was released recently on reading code, called (unsurprisingly) Code Reading. I borrowed it off Dominic and started reading it a while back, but did not get more than about 100 pages through it. It seemed to contain an equal mix between open-source motherhood statements “many eyes make bugs shallow” and tips that anybody who has ever done any maintenance programming has probably already figured out “set break points in the code and step through it to see how it works”. This was about 6 months ago so maybe I am being a little harsh, and it could possibly get better later on.
What code-bases are essential reading for .NET developers? Obviously ROTOR and possibly MONO are golden for anybody working on libraries. Some of the sample from Microsoft like the starter kits and Taskvision should probably be on the list. Andy “MetaBuilder” Smith’s free controls are probably a good starting point for webcontrol builders. What about .Text? Ghengis? SharpDevelop? With a finite amount of time and a wealth of good candidates, what is a developer to do? What about non - .NET code bases? Somebody once told me Don Knuth’s TeX code base was a thing of beauty….maybe I should be reading that.