Formatting code a bad thing when using a VCS

code formatting

I almost always format my code before I commit to make sure it's done properly. Most of my team don't really care and don't always format their code properly (minor things that don't affect the code but affect readability when trying to maintain it).

I recently installed the VS power tools that has an option "Format on save", and made a change to a file that wasn't formatted prior. The development VP just came to me and reprimanded me for formatting since it shows up in the merging tool as having almost the entire file changed, instead of just a line or two (so he can't see exactly what I modified easily), and told me to disable the format on save in the future. While I understand that concern, I find it difficult sometimes to sort through the code that is unformatted, and IMO it should be formatted properly all the time anyways. Note that I'm not just reformatting things on a whim., but as I write code I'll either use the power tool or hit the key command to format the text to make it easier to read, and in SVN this shows up as a modification.

So I ask, is always formatting the code actually a bad thing? Are his concerns more valid than making sure the code is readable?

Best Answer

First off, your team needs to pick a formatting convention and stick with it. You need to come to an agreement and have everyone stick to it so you don't have people fighting over what things should look like. This should not just be something you do on your own.

As for your real question. Formatting code is not a bad thing. What is bad is making major formatting changes in the same commit as code changes. When your team comes to consensus about how things should be formatted, make one pass thru the code and format everything. Check that in by itself. The commit message will make it clear that the changes are just white space and not functional. Then when you need to make functional changes, they are in a different commit so they can be clearly seen.

Related Topic