We create positive world change connecting authentic companies with real people in socially responsible ways.

Wtfm

Comment Your Code

October 02, 2009 by Brandon Weiss

Despite the fact that everyone agrees commenting your code is a good idea, it seems like few developers if any actually do it; especially in web development. I can't remember the last time I opened up an app or site and saw regular comments explaining functionality or what some extra complicated snippet of code was doing.

Worse yet, developers pride themselves on making their code as lean as possible, often refactoring multiple times; the less lines the better. Clever code is great, but without comments it's even harder to understand than its syntactically simpler predecessor.

I think what happens is that most developers work in a vacuum. Sure we might go to dev meetups, and talk shop with our friends, but we're most likely freelancers, or the only people at our companies that fit a particular role (front-end developer, back-end developer, etc.). So we figure that since we're the only people working on the site, is it really necessary to take the extra hours to document our code? Who would we be documenting it for, ourselves?

This type of thinking is endemic, and I'm definitely guilty of it myself, but it's so unbelievably shortsighted. The code we are writing is most likely going to be around long after we are not. We'll leave the company, or get fired, or any number of other possible scenarios. And our legacy will be what? A bunch of unnecessarily complicated — possibly bad — logic that someone else has to muscle through to get anything done? Or worse, has to rewrite completely?

I want someone to look at the work I've done and smile, not wince. I don't want my legacy to be frustration and discontent. So I'm going to start commenting everything that needs it, right now. You should too.

Comments

image placeholder