Wednesday, January 05, 2005

Code to be proud of

I remember back in school there was a girl who always had perfect code. Indented, commented, well thought out variable names, the whole nine yards. I was impressed until I watched her code. She spent too much time cleaning it up rather then just seeing if the code would work that she didn't get all that much done and wasn't having much fun.

Over the years my coding style has improved dramatically. I am not perfect, but am much better then I was ten years ago that is for sure. These days I try to spend a few extra minutes cleaning up my code whenever I go back to old code. Little things like checking to see if all the headers are required, renaming some variables, adding comments, and thinking about if that function I wrote a year ago is still needed.

Just about every job interview I have been on has asked me to present some code. Starting a year or two ago I started thinking that rather then having that one little bit of code (that is perfect) to show off I make it be all my code. That way I can just let them visit my website and let them pick anything they want. It is a win-win. They get to see that I can produce consistant clean code and slowly my code becomes cleaner and easier to maintain.

The only downside is that there is always that code that I never got around to fixing and am embarrassed to show people. But at least I am not alone as there is plenty of bad code out there. I have come across plenty of comments saying something along the lines of "Fix up later" or "TODO: comment". To go with that I have seen plenty of version 0.01 applications that are released that are very small, but at that same time very messy and the developer even brings that up without being asked saying it will be cleaned up for 0.02. One has to wonder if they didn't have the time to clean up the small amount of code for 0.01 when they were the only user what makes them want to clean it up for 0.02 when they have users asking for features? Luckily (for those developers) a lot of open source applications don't go beyond version 0.01 and so no one sees the code.

One reason why this topic hits home so much is the nature of open source and KDE. Your typical KDE developer might not have all of KDE cvs on his local computer, but at least the module he is working on. So inevitably others will look at any code you put into KDE's CVS, good or bad.

Recently I was looking through kwin's code (the KDE window manager) trying to understand how it worked. I discovered that the code was quite clean and consistant. It was very nice. So I want to invite other developers who have spent time in KDE's CVS to share code that you found to be particularly well maintained, organized and clean. A fun public way to say thanks to those developers for taking the time to write clean code they should be proud of.

No comments:

Popular Posts