Documentation: The Unsung Hero

Documentation might not seem essential but once you sit down with thousands of lines of code that 25 people and a dog have had their hands (or paw) in, then you will see why without sufficient documentation you will find yourself in a World of Pain. I can share with you numerous examples and horrifying stories, but you will probably not believe me until you experience this Hell yourself. Well, you are reading this…so maybe you have already experienced this nightmare. I offer my condolence if this is the case and remember “what doesn’t kill us makes us stronger.” Anyway let’s move on, here are some things that I find extremely helpful to have and thus think important to do when writing your documentation.
- First and foremost, comment as you go! This should be a given, but I’ve seen people in college wait until the program was working and met all the requirements to go back and write the documentation. This is after god knows how many changes, count variables added or debug cout statements. How do you expect to be able to write a coherent explanation of something you rewrote 100+ times while you were jacked up on RedBull?
- Use Hungarian Notation – Hungarian Notation is a naming convention where the variable name indicates its data type or intended use. This is more for structured programming languages or hybrid languages like C++ (in a pure OO language, Hungarian Notation has no purpose). For example, if we are retrieving the age of the user and storing it in an integer we could name the variable iAge. If you couldn’t tell by the name “Age” that it would probably be an integer we have an i at the beginning to confirm it. This might not be the best example. Let’s take print, as it is named now we wouldn’t know what it is, but if we change it to fnPrint we know it’s a function or hwndPrint it is a handle to a window, probably the print window :-).
- Document each Function and Class– Each function should be documented before the definition of the function. I have a certain format that I use, but it’s a personal choice. Here is an example of my method.
/////////////////////////////////////////////////////////////////
// BOOL fnStartApp (int iVar1, int iVar2)
//
// IN: iVar1 == *description*
// iVar2 == *description*
// OUT: nothing
// RETURNS: success or failure
//
// This function spawns a new thread that runs an application… * detailed description
// of what this function does, how it works, and any whys that might be needed
//
/////////////////////////////////////////////////////////////////
I start with the declaration of the function. Then I describe what it takes in and what it sends out, I also describe what values the function can return. This is by no means the only way to do this; the most important thing is you answer the questions how and what. Some people suggest including why. As in why you chose to use vectors instead of arrays but these can be saved for an as needed basis. You don’t have to explain your preference for one data type over another.




2 Comments:
Your comment format for step 3 reminds me of the javadoc formula. It's a specifically designed comment that tells what the function is, what its inputs are, and what it outputs. Something like this (in a comment, of course):
@in: int y - describe variable y
@in: int x - describe variable x
@out: int z - describe return value
The cool thing about it is that the java sdk comes with a "javadoc" processor that scans your .java file(s) and outputs an html file that looks like a Java API page.
It's actually quite useful for large projects. Instead of running through thousands of lines of code looking for comments, you can look at html code.
As a side note, the "//" operator isn't ANSI C. Most programmers prefer a comment block like so:
/*
* this is a comment, *
* and another line for *
* specialness. *
*/
(it actually looks better in a monospaced font with no stripped whitespace)
There is a tool called doxygen That works just like javadoc that strips your comments from your code and generates html files. It says it works with C++, C, Java, Objective-C, Python, IDL (Corba and Microsoft flavors) and to some extent PHP, and C#. I've never used it but it seems cool. Also i used to use the /* but the projects that i've taken over at work are all done with // so i've just adopted that method.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home