Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I work for a multi-national I.T. services company. I'd thought they'd be applying good development practices but they aren't. One example is the source code base for a Java project that is currently being developed for a client. It's full of incorrectly indented code. There's mixtures of tabs and spaces on lines (no they're not using the GNU formatting style) as well as 2 or 3 or 4 space indents. Everywhere else I've worked people have agreed to a fixed indentation coding standard and stuck with it, so that's why I find this project an anathema. How do I diplomatically get them to indent properly?

share|improve this question
s/\ \ \ \ /\t/g ? (I say that jokingly). If nobody, until now, has complained about it .. it probably means that nobody but you cares. If you need to fix indentation to make something easier to read, fix it.. otherwise, when in Rome ... –  Tim Post Nov 23 '10 at 12:42
@Tim: Yeah but problem is it's also mis-aligned. In places there are 2 space, 3 space, 4 space indents. –  sashang Nov 23 '10 at 12:44
@sashang - Yes but what's the actual problem it's causing other than offending your sense of neatness and consistency? –  Jon Hopkins Nov 23 '10 at 12:49
@Jon Hopkins - the harder it is to read the harder it is to maintain. If the layout within individual files is inconsistent this makes things worse. –  Murph Nov 23 '10 at 15:31
Write a script to go through the codebase and fix all indentation. Make it part of he build process. –  rmx Nov 23 '10 at 16:51

6 Answers 6

up vote 13 down vote accepted

Does the code run? Is it relatively bug-free? If either is yes, then don't worry about it. No company is going to pay someone to go through the source code and fix indentations. If you're in the code doing something, by all means, fix it.

Perhaps the better approach is to ask someone about your company's coding standard. My guess is that there isn't one. It would be more productive to have one established than to complain about proper indentation.

share|improve this answer
if its a bug from my code, by all means fix it. If theres a better way to do it, please do. If youre gonna muck with my indenting or style and it still complies with team standards, DO NOT TOUCH! –  jellyfishtree Dec 18 '10 at 0:17
Improper indentation could hide real bugs, or slow down developers' ability to work effectively with code. Then there might be a business case for cleaning it up. There are automated tools that could help keep the cost low (indent). –  Craig McQueen Feb 28 '11 at 1:39

Use the campfire rule: Leave the code better off than you found it. This means correcting indent in areas that you touch. Correcting indent in areas that you don't touch can cause a lot of noise in commit histories and diffs.

On the other hand, correcting the culture is both a more worthwhile and far more difficult endeavor. As a general rule, when a small system (you) comes into contact with a larger system (your corporate culture), the small system is far more likely to change than the larger system. The only way to overcome this effect is through persistence and local (rather than global) action.

Work with your peers directly, with patience and determination, to gradually improve the quality of your codebase. Be aware that you will have to sell them on the idea that indentation is important to code quality if you want to move towards consensus and effect a lasting change. Cultures do not change by fiat.

Then again, before embarking on this quest, decide if it's worth it for you.

share|improve this answer

Explain that it makes the code hard to read and compare. Try to agree on a standard. Then automate this by creating appropriate config files for the IDEs that you use or apply the standard automatically when code is checked into source control. Give this time to sink in.

share|improve this answer

If it really bothers you, and you can't simply fix formatting on stuff that you have to work on in order to make it easier to read (i.e. correcting crazy indentation to get everything you need in one screen full), try running the code through ohcount.

This helps you show that 50% of your code base is blank lines, and may reveal that the code is not commented very well (perhaps something else to raise).

Usually, though (as noted in comments) .. when in Rome ... well :)

share|improve this answer

If you think this is of importance, then have some automated tool do the indenting for you.

I don't think you can easily enforce this. Mixed indentation usually comes from many different people working on the same code. If you wanted it to be uniform, you'd have to force some people to change their indentation while others could keep it.

For example we have a mixed brace style at our company. I would never demand my colleagues to change their style, nor would I be keen on changing mine, because I have the responsibility to maintain the code I write so I want it to be as readable as possible in my eyes. Same thing applies to their code. If I go in their code to make a small modification, I try sticking to their style. If its a bigger chunk of code, I stick to mine. It also identifies, who wrote the code. So if it doesn't work, they don't even need SVN to blame me :D

share|improve this answer
Only use automated tools to indent your code retrospectively if you never want to be able to do a meaningful diff again in many version control systems. –  Jon Hopkins Nov 23 '10 at 12:48
@Jon Agreed. We did that on a former OSS codebase I maintained and it has since been a source of considerable frustration. –  Rein Henrichs Apr 12 '11 at 20:03

First ask yourself does it matter.

"Correct" when it comes to indentation is very much subjective and so long as it's broadly clear is there really an issue?

You need to work out how much time is actually going to be invested in this (just the debate of what is correct could take the whole team hours to agree) and whether that's the best way to spend that time.

Personally my view would be that if their development practices are such that you think the biggest issue is code indentation then you should probably be happy that things are in a pretty good way. If on the other hand there are other more significant issues, then you probably want to work on those first.

If you do want to press ahead I'd suggest:

1) Define a standard and get it agreed (good luck with this) and then the rule should be that that standard is applied for all new code and changes going forward.

2) Think very carefully before doing an automatic reformat of any code as this will render it impossible to do a meaningful diff with many version control systems (including but I'm sure not limited to Subversion).

share|improve this answer
I think by "correct" OP meant the non-subjective part of correct indentation: consitency. –  back2dos Nov 23 '10 at 12:44
@back2dos - My answer stands as you still need to get agreement on what the consistent standard to be implemented will be and the chances are that it's not that big an issue. –  Jon Hopkins Nov 23 '10 at 12:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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