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 (6)

  1. Jeff says:

    I think a unified code style for a code base is very important.  If everyone is using the same style, then you can’t tell who wrote what code.  The level of emotional detachment from the code is higher, therefore people are more likely to critique and review the code, without being afraid of the consequences (how many times have we wanted to tell a senior person, that quite frankly their code sucks balls).

    What I really think would be sweet, and one day I’ll get round to writing it, is a source control system that performs a unified syntax transform upon check-in, and updates it to "my" style upon check out.

    Therefore the only code I ever see in the code base is in "my" style.

  2. Max Battcher says:

    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.

  3. MSDNArchive says:

    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.

  4. JohnW says:

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