Jaa


Opening the Coding Style Can of Worms

I find it troubling when different portions of code from the same project use different indentation and bracing styles. In my opinion, it's much easier to read and maintain code that's uniform in style. However, you won't find me arguing that any one style is objectively better than any other. Although I have my own preferences, I've found that my brain and fingers are willing to adapt to any style over time. All that they ask in return is that I try to stick with a single style while working on a single problem.

Unfortunately, our team doesn't have formal coding conventions and our code base has evolved a fair amount of inconsistency over time. I recently asked the team if we could settle on a standard indentation and bracing scheme in the future, but I now regret that I brought it up...

It's very hard to extract the benefit of reaching a consensus on this issue without wasting an inordinate number of cycles arguing about it. At the end of the day, I think I'd rather not discuss it anymore.

I'm reminded of Ken Arnold's article on the subject. Although his proposal is quite radical, it addresses all of my concerns. If we adopted his approach, we'd have 100% consistent code without spending any time arguing about it!

Comments

  • Anonymous
    June 14, 2006
    The comment has been removed

  • Anonymous
    June 14, 2006
    With modern pretty printers so easy to use and easily available I find the code styles matter much less than they used to.  Easy enough just to tell Visual Studio (or Vim) to reformat the document.

  • Anonymous
    June 15, 2006
    Jeff, that's an interesting idea! If you ever get around to building that system, please drop me a note.

    Max, you're right that good editors help the situation considerably. However, this approach doesn't quite work when there isn't a consistent style across the team. If developers have different settings in their editor, then they might accidentally reformat parts of files that they didn't intend to change, which obscures the source control history considerably. It's also harder to take advantage of editor features when you have to work in a mixed style code base. For example, I always have to turn off the option to reformat after each closing brace in VS, and I have to double check my settings and highlight specific blocks before I can safely press Ctrl+K Ctrl+F.

  • Anonymous
    July 17, 2006
    Any discussions about coding style become messy very quickly for sure. Most often than not they seem to turn into a religious war..

  • Anonymous
    June 01, 2009
    PingBack from http://uniformstores.info/story.php?id=5066

  • Anonymous
    June 01, 2009
    PingBack from http://uniformstores.info/story.php?id=19055