« Denial Isn't Just a River in Egypt | Main | Agile Development Presentation »

May 15, 2007

Liar, liar, pants on fire!

Before I start this diatribe, give me a minute to get up on my soapbox. Ah, that’s better. The air up here is not as polluted and I can see more clearly now. Too bad some of you can’t get up on the soapbox with me to enjoy the view, but I digress. OK, before going any further, I warn you that I am about to offend a lot of “kool-aid drinkers”.  If you are one of them, tough toenails, because I’ll give you the bottom line right now – you, my friend, are an idiot.  If you don’t have thick skin, read no further. Those of you brave enough to face the truth, continue on.

We here at Visionpace make every attempt to practice the Agile methodology of software development. We are proud of the fact that this practice serves both us, as software developers, and our clients extremely well. Many of our clients were reluctant at first, but once they understood the benefits, most of them gave it a chance and haven’t looked back.

Agile practices are a good thing, but I do have one beef that I am VERY passionate about and I am about to discuss (some of you might even say, proselytize) it. In many agile discussions, as well as discussions about other software disciplines, one often hears the phrase, “All comments are lies.” Those of you who believe this are (as I have alluded to above) idiots! However, those of you who do NOT believe it, COULD still be an idiot, and so, be sure to get a second opinion.

Hey, I get it. Don’t trust comments. They are not always accurate. Duh! I feel that there are a certain percentage of you out there who actually embrace this belief because it validates the fact that you were doing the right thing all those years by NOT putting comments in your code. No, it just validates that you are lazy. Lazy is not, necessarily, a bad trait in a software developer, but NOT commenting your code WITHIN the code makes you, dare I say it, an idiot. That is the last time I will use that term, because, hopefully by now, you are riled up enough to really listen to me.

Other than the fact that someone either knowingly wrote an inaccurate comment or wrote a comment, modified the code pertaining to it, and then did not update the comment, can any one out there give me a reason NOT to trust a comment you discover in code? We will exclude that person from the discussion because he is a “psycho programmer”; you know the one that NEVER follows any kind of standard and use one character mvars. Besides, most “psycho programmers” don’t comment anyway.

Here are the reasons why you SHOULD comment your code.

  1. Let’s get the “trust” issue out of the way right now.  If YOU put the comment in yourself, you BETTER believe that the comment is accurate. You did it (primarily) for yourself.  The fact that an accurate comment will benefit a maintenance programmer who comes down the pike a year later is an extra benefit; a benefit which I appreciate when I am called in to do the maintenance. I will be more than happy to ASSume that the newly discovered comment is accurate because THAT developer put it in there and, like you, why would they want to lie to them self? Yes, there is that chance that the comment is now inaccurate.  Studies have shown, statistically, that approximately 93% of comments ARE accurate.  Right here, you should be asking yourself where I got those numbers, and right here, I will tell you that I made them up.  Who would waste their time researching that fact? Nevertheless, think about it, most comments ARE accurate because the person who writes them WANTS them to be accurate.

  1. OK, I can tell you are getting a little bit peeved right now. Dave, I thought our code is supposed to be “self-documenting”? If I write bug free code, why do I have to comment? Oh, grasshopper, you will learn someday.  Until then, trust me, write those comments! In all honesty, I, too, am a believer that under most circumstances, the code SHOULD be self documenting. However, consider the following code:

REPLACE Name WITH UPPER(SUBST (LastName, 1, 2) + LOWER(SUBST (LastName, 3)


That code is self documenting, if someone wanted to take the time to figure out what it does, they could easily do so. The real question the person should be asking their self is... WHY is that code there? It looks kind of goofy anyway.  When I first saw it, I thought that perhaps the coder didn’t know about the PROPER function, but then, they were really capitalizing the first TWO letters of the name. Maybe the parameter of the first substring should have been 1, 1.  Maybe I should refactor using the PROPER function.  I am soooooooo confused!  Close to an hour of my time was spent determining WHY this code was here.  Imagine how much easier it would have been had the following comment been in place.

DLA/Visionpace 04-01-2004 Mr. Jones, the COO, bought 113 file cabinets at an auction. He has decided that the new company wide filing system will be based on the first TWO letters of the customer name. EACH drawer will have a two letter designation and the file will be placed in the drawer base on the first two letters of the customer name. To make it easier to file, he wants the first two letters emphasized for easier reading.

Immediately, we can see that the code is correct and that there is a reason WHY it was written.  Additionally, as often happens to me, in some scrum, when asked why this was done or who requested it, the answer is there.  Not only for me, but for you when you come in to do the maintenance. Two minutes to initially write the comment or 60 minutes to figure out the details three years later. You do the math.

  1. Additionally, what one developer feels is self-documenting, another might not. Why not eliminate any potential confusion and explain the reason for the code’s existence? Again, it will save the next person who comes along much valuable time for there is a real good chance that they will know nothing about the project and the code. Believe me, you will benefit also.  One of my favorite phrases is... “When you are coding, you and God know what you are doing.  Six months later, only God knows.” I can not begin to tell you the number of times when I have gone into some legacy code and the comment I wrote three years earlier IMMEDIATELY brings back to life the exact reason for the code.  Many is the time that it has saved my fanny. Those are the times that I almost dislocate my shoulder patting myself on the back for a job well-done.

If you have made it this far, you are just not getting enough billable hours in.  However, thank you for reading along and agreeing or disagreeing.  Either way, I would appreciate hearing your thoughts on this very polarizing topic. I promise to bring an open mind if you do the same, but I will say right up front, that it will take a Herculean effort to change my mind.  Care to give it a try?

Posted by Dave Aring on May 15, 2007 | Permalink

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/384091/18478290

Listed below are links to weblogs that reference Liar, liar, pants on fire!:

Comments

Hello Dave, as you expected you have drawn a dissenter. I am a firm believer that code should be self documenting. I am upset however for two specific reasons. 1. You quote a statistical number that you admit is completely made up. 2. That you think "REPLACE Name WITH UPPER(SUBST (LastName, 1, 2) + LOWER(SUBST (LastName, 3)" is acceptable code. This should never pass a code review unless it was a one line method with a name like: ReplaceNameWithFilingName().

Thank you for your thoughts and challenging my assumptions,

-d

Posted by: Dru Sellers | Jun 7, 2007 8:52:21 AM

Dru...

It is a good thing that it is breakfast time because you offer some “food for thought”. I HOPE that you aren’t really ”upset”. Irritated is fine. So is “reeling at the stupidity of the blogger”, but don’t be upset.

Addressing your points one by one... The statistic I quoted was meant to me a joke. Personally, I don’t believe in putting smilie faces after a joke. I hope that I am able to make a joke without having to tell you that it is a joke. On the other hand, perhaps, I SHOULD be using smilie faces. Either that or ACTUALLY develop a truly humorous writing style.

OK, you caught me. You caught the “tator”. My example was NOT a real-world example. It was a lame attempt on my part to come up with some code that was (hopefully) not self-documenting from the standpoint of WHY someone would write the code. You are absolutely correct, Dru, in that I did not place the code into a method. My bad. I am ASSuming that your point is that with a descriptive method name like ReplaceNameWithFilingName() it would indicate what the code is supposed to do and would be self-documenting. No argument from me on that point. However, my real point is... WHY was it being done? Neither the method name nor the code within the method answers that question. Now, one could argue that “it isn’t my job, man” to know why that code was there. The developer just has to make sure that the code that is there works as desired. I would argue that this is the PERFECT location to document (primarily for the developer’s benefit) the “whys” of the code’s existence.

Again, here is my reasoning. A good developer is part of a team whose collective goal is to create the best version of the software that is humanly possible. As a team member, each person has specific duties, but since they are part of the team, they should also do whatever they can to make the whole team better. This would include having answers whenever possible. As I said, I have been in many review meetings over the years where questions came up about “why did we do it this way?” and no one remembered or there were several different remembrances. At the time, I will admit, I had my version of the answer, but wasn’t sure it was any more correct than the others. However, when I went in to review the actual source code, many times my comments explained everything with respect to why we did what we did. As often is the case, the written word carries much more weight than the recollections of something that happened two and half years earlier. On several occasions, I was reminded that we HAD to do it the way we did BECAUSE of a certain set of circumstances at the time. These thoughts and comments remove any doubt or speculation about the “whys” of code. You, as a developer, have helped the team. The important information was right there with the code. It was not on some legal pad of meeting notes or in some RFP (where no one would look anyway).

Bottom line... I am only SUGGESTING that developers take the little extra time required to add meaningful comments about the source code WITHIN the source code because, eventually, many of the comments will be found to be useful and informative. At least, that has been my experience. HOW MUCH of this type of documentation you do depends on how important it is to you. After all, the comments are for you or for the next developer who comes along (and most certainly will know nothing about the “whys”).

My mantra for the day is... It’s wise to document “whys”. Thanks for the input, Dru. Any second thoughts?

Posted by: Dave Aring | Jun 7, 2007 10:09:54 AM

Post a comment