I was wondering how people deal with working in a project with badly written and formatted code, I'm talking mixed tabs and spaces, unnecessary parentheses and newlines and a whole bunch of warnings appearing on the code from the IDE. For context I have this problem on java projects, where no formatting was agreed upon. Also, in my case they are projects that have not gone public yet.

The possible solutions I can see are:

  1. Try and talk to the team leader/code owner, agree to a formatting and reformat everything in one commit. (my preferred choice)
  2. Format the piece or pieces of code that you have to change, commit, then make the change and commit (second best)
  3. Deal with it, make your changes as minimal as possible, leaving everything else as was.. (worst choice, for me)
  • The spacing is not very important. The IDE warnings are!
    – user1249
    May 24, 2012 at 14:08

3 Answers 3


I agree with your choices and their order. Keep in mind that if you format the code as you go along without an agreed coding guideline, you will most likely end up playing code format ping-pong with your co-workers who are working on the same files.

Also, don't cling to your particular formatting: as long as there is a consistent guideline, the code will be readable (everyone will have to adjust to read/write the code in that format efficiently, but that's the price you have to pay and it is a "one-time" investment up front)


Remember the Boy Scout Rule, leave the code cleaner than the way you found it.

Therefore I'd suggest to get the Team to agree on a code formatting guideline, and then apply 2. You will keep productivity up and you will improve the code as you go.

If you need strong arguments for why code should be kept clean, I do recommend reading the Clean Code book. People need to be able to read and understand the code. The better it is formatted, the faster everyone will be able to read it. Machines (Diff/Merge) also do a heck of a lot better if the code is uniformly formatted.

If there are discussions about what is the best formatting, remember there is no such thing. I fully agree with @Attila here: As a consultant I have moved from team to team and after a few weeks anyone can get used to the same style of code. Most of the strong 'feelings' about code formatting are born out of habit.


A standard should be set for sure, or you will have each team member committing to a project with different code-formatting styles. I would talk to the team leader about this before talking about reformatting code.

If no formatting continues to be the standard for this project, format your code the way you see fit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.