Software geeks can be a touchy lot from time to time. I had to share some soothing words with a coworker who'd gotten a little fired up about someone changing the formatting of his code. (OK, so I also took the time to crack a little joke about that being understandable since he never formats his code to fit in an 80-column window.) While his reaction to this infraction might have been over the top, I do have to stand with him on principle. Maybe it's just the concept of ownership -- it's not my code unless it looks like my code. Maybe we just take pride in our work. Or maybe we're all just nit-picking perfectionists.
My personal preference runs something like the following: curly braces go on their own lines, four space indentations, NO tabs, and everything formatted for an 80-column window. Parentheses go with the expressions, not the function/keyword. Comments are set apart for easy reading (formatted as haiku or limericks or plain old prose, depending on my mood).
/*
* My comments tend to go something like
* this most of the time.
*/
if (x > 0)
{
printf("Do something!\n");
}
I like that kind of code. OK, so it has a lot of whitespace. Disk space and memory are cheap these days. I find this type of code easy to maintain, easy to read, easy to understand. But I must be out of touch with the rest of the programming world, because I've found the following (or something like it) to be much more common:
/* This comment is just a hat, barely distinguishable from the code */
if(x > 0){
printf("Do something!\n");
}
Sure, it's compressed, fitting more code into a tighter space. It's a little more effort to figure out what things are doing (especially if you miss that curly brace on the same line as your statement). And, frankly, I just don't find it aesthetically pleasing. Browsing through code like that is akin to a trip through a museum of modern art -- I go away scratching my head and thinking, "What the heck was that?"
And yes, I'm the type of guy who's wasted a little bit of time reformatting code to my liking, especially if I'm forced to spend any length of time editing it. Ownership? Pride? Or nit-picking perfectionism? I think I'll go with the latter.
Recent Comments