Fog Creek Software
Discussion Board

What source code are you reading?

I find it interesting to read and study source code from various projects.  I'm currently reading and studying the source code to :

Jagged Alliance (game)

Does anyone have any recommended source code to read or study?

Source Code Reader
Wednesday, July 21, 2004

Want my first professional project? It'll keep you glued for years to come....

Wednesday, July 21, 2004

I probably read the Windows source code the most (I have legal access to it). Lots of nuggets in there.

Wednesday, July 21, 2004

The Linux Kernel
tcc (Tiny C compiler)
lcc (local? C compiler) is your friend - find a project you find interesting, and starting reading the source.

Ori Berger
Wednesday, July 21, 2004

Reading source code is not particularly useful, particularly the crappy source code the makes up the vast majority of OSS projects.

Are you guys just really fucking bored?

Wednesday, July 21, 2004

To be fair, the vast majority of closed source projects also consist of crappy code.

Wednesday, July 21, 2004

I am looking at GMail's JavaScript :)

Wednesday, July 21, 2004

I personally enjoy reading kernel, web server, network stacks, and proxy server sources. Apache was commented on. Minix and Linux was commented on. Linux net stack was commented on. Forgot the name of the publisher. It's easier to read in print and with a little bit of help. If you can handle huge softwares that's great, but generally I stick to the little things (small web servers or web accelerators) still in alpha to keep the reading to a minimum.

Li-fan Chen
Wednesday, July 21, 2004

Another fun thing to do to keep the reading to a minimum is reading libraries written in Javascript or some other high level scripting language. You learn a lot about a concept or the plumbing without getting all wet. Things worth reading include XML-RPC server and client libraries, encryption libraries, device drivers, thunking/wrapper software (software that translate your javascript into calls to c).

Li-fan Chen
Wednesday, July 21, 2004


What proxy servers have you looked at?  I've written a HTTP proxy server from scratch, and I have admit it was far more work than I ever imagined, although it has some characteristics that I didn't find in any OpenSource servers. 

Squid is pretty neat, but somehow the configuration seems overly complicated.  It was also orginally written as a level-triggered server, and while there are hacks to make it work edge-triggered with sys_epoll(), I'm not totally convinced I would trust them in production. 

christopher (
Thursday, July 22, 2004



Li-fan Chen
Thursday, July 22, 2004

Squid is interesting in that it uses a single threaded model.  Another interesting http server is thttpd.  The whole thing is like 5 C files. 

christopher (
Thursday, July 22, 2004

Mr. Fancypants - I understand you grasp all useful techniques and coding issues from the ether, but some of us don't have the capability -- and we improve ourselves by learning from others. You know, like writers read other writers' books every once in a while.

The projects I listed above have high quality source. If you ever bothered to read code, you might have known that.

Ori Berger
Thursday, July 22, 2004

I am working my way through the .NET framework at the moment. Some of the code does seem very naïve, but I guess that's probably the optimiser, rather than the MS guys ;-)

Thursday, July 22, 2004

How do you read source code?  I'd like to know.

I can think of nothing more baffling than encountering a code base for the first time, especiall C++ stuff.

What do you take as you starting point?  How do you go about figuring out templates and other preprocessor stuff.

Any good tips.  Donald Knuth says that he takes a set of random pages and gets to know them really well.  Anybody else try this?

Do you find OO code easier to read or functional?

Ged Byrne
Thursday, July 22, 2004

Procedural is usually easiest to read; Nothing inherent, I think, but that's my experience.

I usually read a few random .h files with interesting names, then a few random .c files with interesting names. I take notes (usually with a pencil) while I do that, and then start the quest with resolving my notes.

You might find running Doxygen in it's "collect every info" mode useful, and browse through it (you can also print, although it will require a forest or two).

Or you can browse the documented Doxygen online.

Or maybe RedHat's SourceNavigator (which also works on Windows), which is also a good source reading tool.

But essentially, "less" or "notepad" should be sufficient after you've grown the habit.

Ori Berger
Thursday, July 22, 2004

Ged: It helps when you have a pretty good idea how something works, then you're just checking your understanding, though still with the occassional suprise, of course.

I've spent quite a while looking at the .NET code and I have to say that Reflector does a good job in presenting it in an easy to use way. I normally view the code in C#-equivalent, but you can view it in IL, VB.NET or Delphi too.

Thursday, July 22, 2004

Golgotha & Abuse, the games from (C++, lisp)
Half-Life 2 (very rich sound effect library, btw; C++)
Quake2 (C)
K3d, modelling software (C++, nice scripting API)
Qt (C++)

By the way, I have yet to find a PHP source code I'd call beautiful and easy to read.

Thursday, July 22, 2004

I usually start with the highest level and go down, i.e. I start with the GUI (if there is one), move down to the next highest-function set, and go from there, looking up the code for functions as I encounter them, until I get to the "bottom".  It's easy to make a diagram of how the code works from this, if you have a big sheet of paper or visio, or some other tool like visio (preferred to do it electronically, or your diagram is going to have a LOT of overlapping lines, unless you're superman at predicting entanglements, and if you are, sweet!)

Thursday, July 22, 2004

Thanks for the replies guys.  Thought I would add some more:

Povray (C)
Fractint (C; Still a DOS program I believe unless run under X-Windows;)

Source Code Reader
Thursday, July 22, 2004

Ohh yea... and I normally identity a feature the program has (by using it) that I would like to know how it works and then I try to find the appropriate source code.  (Sorry, that sentence is wordy heh.)

Source Code Reader
Thursday, July 22, 2004

>How do you read source code?  I'd like to know.

>I can think of nothing more baffling than encountering a code base for the first time, especially C++ stuff.

I would like to recommend the following book:

The book covers your questions, and then some. It is also helpful if you "inherit" some huge codebase.

What code am I looking at this time?

Thursday, July 22, 2004

I prefer developing to reading other peoples' source code. In fact, I can't think of anything I less enjoy than reading other peoples' code. I've never been a maintenance programmer and never will be.

Thursday, July 22, 2004

I tend to use "Understand for C", by to read other people's code.  You feed this tool a list of subdirectories containing source code.  It traverses the subdirs, building a database of all calls, references, objects, etc.

You can then easily generate navigable structure charts of the code, a class diagram of each object, find the 'main' routine (or routines).  You can right-click on a 'call' and immediately go to the definition of the call.

When given a mess of several hundred thousand lines of code, spread over 20 different directories, this tool lets me navigate it in a focussed way.

I don't work for the company by the way, I just really-really like this tool.  It costs around $500.00 for a single license, too, so its not outrageously expensive.

Thursday, July 22, 2004

AllanL5 isn’t that called reverse engineering? You generate design diagrams from the code. I think that is useful to understand how an application has been programmed and designed.  But if you need to change the design can you use the tool to rebuild the code again? Have anyone had any experience with these kind of tools? How is the quality of the code generated? Is it readable?

Cecilia Loureiro
Thursday, July 22, 2004

Why yes, I believe that IS called 'reverse engineering'.  I seem to do it an awful lot -- except I'm only reverse engineering what others have authorized me to reverse engineer.

The 'Understand for C' product basically provides you with a smart editor, with syntax highlighting and multi-file/multi-subdirectory navigation.  I find the smart navigation very useful, and the 'graphic display' of my program also gives me an overview.

If you change the text, you can 're-parse' the set of files, and the change will then be reflected in the graphics it generates.  Unfortunately, its graphics are not really suitable for publishing in a document (yet).

Now, UMLStudio (a different product) does both 'forward' and 'reverse' engineering.  In 'forward' engineering, you draw your classes and hit 'generate'.  It then generates a set of .H and .CPP files to instantiate your classes.  You still have to write the class bodies. 

'Reverse' engineering works also.  You give it a subdirectory, and it will generate diagrams based on the .H files class descriptions. 

The problem with this 'forward' and 'reverse' engineering approach is that UML does not (yet) have enough detail to unambiguosly specify what code to generate.  So the full 'round-trip' engineering process seems to lose some detail sometimes.

Thursday, July 22, 2004

Apache Struts, because the documentation has some frustrating holes in it.

Justin Johnson
Thursday, July 22, 2004

I'm just getting into TDD, so any tutorials / examples of that.  I'm not a mature enough programmer to tackle reading a major product (i.e. Apache or Mozilla) and grok it.  I think once I grasped one section it would fall out of my brain as soon as I pushed another one in.

Any recommendations on a small but complete project I could start out with, preferably in something higher level than C/C++?

And yes, as an employed PHP programmer and PHP lover, I can agree, there is no large PHP project whose code is less than insane.  But hey, at least it's not Perl.

Friday, July 23, 2004

For getting to know C++ techniques a bit better I recommend reading the Boost libraries. The MFC C++ library is good reading, and if you are into Delphi try the VCL (Visual component library). The VCL is actually easily read.

Christopher Diggins
Sunday, July 25, 2004

*  Recent Topics

*  Fog Creek Home