🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Brain Giblets Volume V: Justified Procrastination

Published July 09, 2008
Advertisement
Alright, ladies and germs, go get your controversy hats and make sure they're snugly mounted on your head - I'm going to drop a bombshell here.


Documentation in General
Everyone should hopefully already agree that documenting one's code is a good practice. Interfaces for libraries or self-contained modules should come with complete descriptions of how to use the interface itself, potential pitfalls, and so on. Internally, code should be sprinkled with comments that describe why certain algorithmic choices were made, how various design decisions were reached, and so on.

Now, documentation styles are as varied as programmers themselves - so I'm not going to get into any specific details of how to document code. That's a largely personal decision, and in my opinion it's something that one can easily decide will a little bit of careful thought and some common sense.

So instead, I'll be approaching a topic that is much more rarely discussed - when to do documentation.


The Prevalent Opinion
The conventional wisdom - and my own view for a long time - is that the best time to do documentation is right after you write the code. Everything is still fresh in your mind, the details of each decision are still clear, and generally things are still "warm." This seems like an ideal time to document code.

Sometimes, we might even want to pre-document code - that is, write documentation before any code is in place. This is typically a good idea when defining an interface for a library or some similarly contained module, where it is important that certain interface constraints and behaviours be met.

Pre-documentation is also a convenient way to explore new algorithms. First, write up a list of basic steps that the algorithm needs to perform, then slowly replace those comments with lines of code that accomplish what the comments indicated. Eventually, you finish all the replacements, and voila - working algorithm implementation (hopefully, anyways).

This is all well and good, but I think there's a better option.


The Bombshell
Here's my suggestion, stated simply: document code a long time after you write it. Put it off as long as practical within the constraints of your project.

Now why the hell would I say something so clearly insane? Procrastination is death, surely; with all that time between code and documentation, isn't it inevitable that something will fall through the cracks or just plain be remembered incorrectly?


My answer to this is it all depends on how careful you are during documentation. I suggest two passes: first, document the code the way you think you remember it works - or, even better, how it is supposed to work. Then, perform a code review.

During the code review, carefully analyze the code and make sure it lines up with the documentation. Remember, your memory is probably fuzzy here, so you'll have to think critically about each and every line of code to make sure that it (A) is correct and (B) matches the documentation.

I'm aware that this is going to be a weird concept for most people, because it runs so counter to the general expectations of how the mind works when coding and documenting. So let's go over the specific benefits of this method:

  • You can get code done without worrying about documenting it until after the fact. This can come in handy when working on a tight deadline.

  • This method works well with agile methodologies or general sprint-oriented development practices; do one sprint to write the code, then do a shorter sprint to document the oldest code which currently needs documentation.

  • By allowing yourself to forget how the code works, you force yourself to be analytical and review the code as if you'd never seen it before. This is a tremendous benefit - the single major problem with reviewing code is that it is easy to ignore or skip things because you're too close to the system to see the flaws. Stepping back for a significant time alleviates this danger.

  • If you have the staff, this is a great way to get everyone to understand critical central systems. For instance, if Joe writes a library that Bob and Frank will be using, Joe first writes the documentation, then hands off the completed package to Bob and Frank, who then perform the code review process. Now Bob and Frank are fully educated on how the module should work, and Joe gets the bonus of having a very carefully peer-reviewed chunk of code.



So there's my bit of programming heresy for the week. Now you can properly enjoy your procrastination, secure in the knowledge that it's actually making your work better!
0 likes 3 comments

Comments

LachlanL
Stoke up the heretic-burnin' fires boys! We got us some fresh kindlin'!
July 09, 2008 06:03 PM
jollyjeffers
Interesting bombshell. Problem is that it relies on discipline - in practice it'll get pushed back and back and put off until the original developers are long since in the grave from old age [smile]

That said, any complex system could do with a "settling period" before any serious documentation is undertaken. Give it a sprint or two to ensure the thing works as expected and satisfies the requirements then document it.

I've seen a lot of internal documentation on components where the developer wrote it up, then it got changed because someone found a problem almost immediately and the docs never got updated...
July 10, 2008 07:17 AM
NineYearCycle
The biggest problem we have where I work is that no-one has ever documented _any_ of the code. We're also given no time nor opportunity to write any documentation. We don't even have doxygen auto-generated stuff which would be immensely helpful. So if possible I'd like to advocate, very strongly, pre-doc, current-doc and post-documenting what you're working on... because otherwise it never gets written in any shape or form and thus what should be a 15 minutes task becomes 4 days of investigation of unfamiliar codebase followed by 15 minutes of fixing/changing the feature.
July 12, 2008 07:11 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement