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?
|
|
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. |
|||||||
|
|
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. |
|||
|
|
|
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. |
|||
|
|
|
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 :) |
|||
|
|
|
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 |
|||||||
|
|
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). |
|||||
|
