Learn to Read the Source, Luke

The source may well be the most up to date and the ‘truth’, but it is by no means correct.

Although not a big fan of documenting the obvious I think that specifications should be mandatory, this way you know what the expectations were of the application, and the source code can not, and should not be the definitive source of such information. However I do agree that, particularly when bug fixing, you should be drilling down straight into the source and not much else if you want a speedy resolution, and all developers should be capable of doing this.

I think documentation pays off when you are providing reusable frameworks and other software, and even then it should be basic guidelines etc.

Damnit Jeff, I just spent the last 20 minutes looking for an easter egg in your html source code.

I agree with K Lawrence. The source code says what the application/library/widget does, not what is supposed to do. Some kind of documentation is needed.

Whenever I use a method or library created by someone else, inside my company or outside I don’t want to look into the source code unless unavoidable. I just want to know how to call it, or what it does, or what is the flow.

For self-improving reasons I will want to read the code. But for the completion of the work, shouldn’t be necessary.

While there are some correct observations regarding the availability of source code, i’d like to focus at the start of the article, where i strongly disagree.
In short, it says “Documentation always suck in many ways and it will always do. Don’t even lose your time with it, just read the code”. And since it is useless this also implies that you should not bother to write it. That’s absolutely WRONG in my opinion.

A complete documentation is important, it’s not just a reference to what a function does. It also tells you what classes are available and when you should use them. If it is properly written it’s much better than trying to read the source cose which may use a syntax you’re not used to and various implementation details that you can’t know. Try to read subversion source code.
Just yesterday i was reading a discussion on git where the developer used Javascript implicit statement separator (which means you don’t put the semicolon) and expression short-circuit instead of a normal if statement. The first of these even breaks some javascript minimizers. Am i supposed to read the code, understand these patterns, figure out what they’re doing and what that var is used to instead of just reading a good documentation? That’s crazy.

Good documentation is a must, don’t oversee it.

So it is possible to read someone elses code afterall!

Sigh. So, another blow for cowboy/hero coding is struck. “Documentation is haaard!” So… just give up?

No. Documentation is essential. Sorry. If your code is clear, concise, self-documenting, that’s great, I totally support that (and, even if it’s not, I still want your source code), but I want to point out that that sort of lovely self-documenting code comes about because the coder thought of the person to come after, so that coder actually wrote DOCUMENTATION (it just happens to be executable).

Coding in a furball, piling up hacks, refusing to document and then handing the whole steaming mess to somebody who asks questions is chickenshit.

I have so had it with people using agile and “use the source, Luke” as an excuse for bad behavior. Yes, I know that if developers had the kind of social skills required for writing good documentation (as in: understanding the audience enough to know what questions they’ll have, given that they’re not an exact clone of you, the developer) they’d be something besides coders, but the answer is not “give up and tell 'em to read the code.”

This is a contentious view because everyone has their own experience of code and documentation.

A few thousand lines of source code doesn’t need much documentation.

Tens of millions of lines probably needs some.

A trivial system probably doesn’t need much.

A complex system probably does.

A system with lots of external interfaces and dependencies probably needs some.

Where I think all experienced developers agree is that code must be written with support and maintenance in mind.

http://cvmountain.com/2011/09/whats-wrong-with-this-code-really/

Whether or not the system also needs documentation depends on the system and the context in which it will be maintained over its life.

This is one of the reasons I don’t like abstraction layers. You can’t predict exactly what they’re going to do, and you [mostly] can’t read the source code to find out.

I think I appreciate the point you’re trying to make and I agree that people would do well to learn to read the source.

However, I disagree with your statement “No matter what the documentation says, the source code is the ultimate truth, the best and most definitive and up-to-date documentation you’re likely to find.”

(Good) documentation is a description of what the software designer/programmer wanted to write, the code is what they ended up writing. If all goes well, these two are the same. But if mistakes were made, odds are only one of the two is wrong and the other offers a clue what was really intended.

Note that this also implies that, sometimes, the code can help fix broken documentation.

This seems to be inspired by your post:

http://blog.ezyang.com/2012/04/use-the-source-dont-read-it/

When I read this a couple of hours ago I agreed with it 100%, then I read about the publication of the original Prince Of Persia source code on GitHub and, although the snifter of Brandy was a tumbler of Bechrovka, sat down for a fine evening of reading through someone else’s code!

Link: https://github.com/jmechner/Prince-of-Persia-Apple-II

Reading the source code is not the solution to bad documentation, contributing to fixing the documentation is the proper thing to do.

Relying on source code and bypassing official documentation is asking for trouble. The source code may reveal undocumented features that are not guaranteed to be available in future versions of frameworks.

I’ve written a more expanded response on my blog (http://priscimon.com/blog/2012/04/17/what-the-source-code/).

Doesn’t Stack Overflow run on a closed source stack?

Best quote from someone in the trenches:

And most of the time, what inexperienced developers consider beautiful is superficial, and what they consider ugly, is battle-hardened production-ready code from master hackers.

Ole Eichhorn: “This is one of the reasons I don’t like abstraction layers. You can’t predict exactly what they’re going to do, and you [mostly] can’t read the source code to find out.”

I have the EXACT SAME issue with projects that use inversion-of-control. Makes it IMPOSSIBLE to figure out the flow of the code unless you’re using a debugger!

I also hate the current “minification” trend in web dev, because it creates source that’s completely indecipherable. Yes, I can go grab the un-minified version from the original site, but what if a specific website has made their own changes?

Code should not need documentation external to the code itself to be understandable. Fin.

I only partially agree with your statement. Reading the source is important, but reading the source is time-consuming.

When you have time contstraints, having code (especially third party libraries) where documentation and code are coherent in behaviour, and especially where all available functions (i.e. public API) are well documented, that’s a real plus and speaks for the quality of the “supplier”.
When you have API and code that don’t match, a load of undocumented features and you go on by (even obvious) trial and error, that’s not good because you always have in the back of your mind the idea that the block/component/library you’re using is not production ready and can become a thorn in your side.

Then, of course, reading a WELL WRITTEN and WELL DOCUMENTED source is a way to improve oneself, as much as reading a book in a foreign language you want to master.

I agree with the final statement from Zmaster: “Good documentation is a must, don’t oversee it.”

@Jeff

Didn’t you develop StackOverflow on the Microsoft stack? I remember a post from way back justifying the decision.

How are you holding these “Use the source Luke” and using Microsoft stack ideas simultaneously?

Or have you changed your opinion on using the MS stack?

@Dehaul
With tools like reflector, you can look into the .NET framework fairly easily.

@Jeff
Your related posts link doesn’t work with middle click. IT simply opens the page in the same tab instead of a new one. Do me a favor, read the source and fix it. It’s annoying. I’d do it myself, but you’d be angry :slight_smile:

I had a friend who always said: “Moses brought the source code down from the mountain, not the documentation.”

Shameless plug but with the honest intent to help out those who find code reading difficult.

We are starting a free code reading study group. Initially it will be ruby, but we have plans for js.

We’re just getting started and currently discussing our first project to explore. So far 150 people have signed up so it should make for some good discussion and study.

If you are interested please checkout

https://tinyletter.com/codereading

This is non commercial and in totally in the spirit of helping out each other.