How to deal with different programming styles in a team?

We have a small dev team (only 3 developers) and we recently got a new team member. While he is a smart coder, his coding style is completely different from ours. Our existing code base contains mostly readable, clean and maintainable code, but the new team member is quickly changing many files, introducing ugly hacks and shortcuts, using defines all over the place, adding functions in the wrong places, etc. My question is if others have experienced such a situation before, and if anyone has tips on how to talk to him.

asked Nov 13, 2011 at 4:00 947 6 6 silver badges 8 8 bronze badges Considered using peer review to catch the ugly hacks and shortcuts before they reach the repository? Commented Nov 13, 2011 at 14:57 Use good, unbiased automated tools whenever you can. Commented Nov 13, 2011 at 16:06

Coding standards can largely be automated nowadays. Requiring people to run each source file through whatever tool you are using before checking the file in will go a long way towards preventing most coding standards violations. I guess what the tools won't catch are the hackers with really ugly practices like the OP's new person sounds like. Seems like code reviews and rejecting undesired styles is about the only way to fix a hacker.

Commented May 28, 2015 at 21:43

7 Answers 7

I work with a team that grew from 2 developers to 10 in less than a year. I was number 3, and the first to raise a coding standards issue. The two original developers had been working side by side for a few years and they'd adopted a common standard that seemed alien to me. We had exactly the same problems you are describing.

What we did was:

Research coding standards

We spent a few days checking out established open source projects. We knew the team would expand rapidly and we were looking for real solutions based on real projects not some generic guidelines. Also we didn't care for the optimal coding standards, but for a set of rules and guidelines that would make sense and not call for the refactoring of all of our codebase. We were looking for a coding standards hack if you will.

The three of us decided that the best coding standards out there for an established PHP project were those followed by Zend Framework. Fortunately the Zend Framework people provide a very comprehensive coding standards document.

Creating our own coding standards

Of course applying another project's coding standards on our project as is didn't make sense. We use the Zend Framework document as a template:

So we had a fairly large document at our hands, stored in our fancy wiki, it was a nice read, agreed upon by all of us. And completely useless on its own.

Staying true to our promise

Our codebase at the time was about 1*10^6 sloc. We knew that since we adopted formal coding standards we had to start refactoring our code, but at the time we were pressed with other issues. So we decided to just refactor our very core libraries, a mere 5*10^3 sloc.

We assigned one of us to be the coding standards master (we used local profanity in place of master) with the responsibility of checking and enforcing the standards. We recycle the role every few sprints. I was the first, and it was a lot of work, as I had to monitor almost every commit.

We had several new discussions and small addendums to the original document during my tenure, and finally we had a somewhat stable document. We change it every now and then but most of these changes are on new features of the language, as PHP 5.3 was a major release in all but name.

Dealing with the new guy

When the next new guy arrived, it was time to put our coding standards to the test. After a small introduction to our codebase, we asked him to evaluate our coding standards document. He almost cried. It appeared that he did everything differently.

As I was the coding standards master at the time, it was up to me to evaluate his input and revise the document accordingly. His proposals were:

For the next couple of weeks he was assigned a simple task: Bring several parts of our codebase up to date with the standards. I had to carefully choose those parts based on a few rules:

I monitored his process and he did a fine job. We identified several parts of code that was impossible to fit our document and revised accordingly (code and / or standards, whichever made more sense)

And then another new guy arrived. We repeated the process (different master this time), and it worked again. And again.

In conclusion

  1. Create a coding standards document, but make sure that your standards are not exclusively your own but do reflect common standards in the wider community of your platform.
  2. Assign a similar role to our coding standards master. Someone to monitor at least new code, and especially new code from new members. Recycle the role, as it's extremely boring.
  3. Always evaluate input from a new member. Always revise your standards if it makes sense. Your coding standards document should be evolving, but slowly. You don't want to re-refactor your codebase at each iteration.
  4. Allow for some time for each new member to learn and adapt to your standards and conventions. Learn by doing works best in these situations.
  5. Wiki works wonders for such documents.
  6. Code reviews work wonders for any situation!

At some point in the process it was suggested that we use a pre-commit hook to automate checking of the standards. We decided against it for a variety of reasons, there are some interesting discussions on StackOverflow on the issue:

Some are PHP specific, but the answers apply to all platforms.