The importance of using a shared coding style in teams

Implementing a shared coding style within a development team can increase productivity and make life easier.

Kit Barnes running a shared coding style presentation

Why should we have a shared code style?

  • Produces consistent code across the project
  • Allows developers to work more easily on code they have not written
  • Reduces likelihood of bugs in code/easier to track down

How to implement a shared coding style

It is likely that developers will be used to using di erent coding styles, from how classes, variables and methods are named to error handling conventions.

  • No single right answer
  • Either use someone else’s or design your own
  • Both methods have pros and cons

Using a pre-made style

  • Likely to come with pre built tools for checking
  • Known to be a successful style
  • Could be too rigid

Creating a style

  • As rigid or flexible as needed
  • Developers might be happier following a standard they created
  • Requires more set up effort (creating style and setting up ide)

Using third party tools

  • Pre-compile source code checking (StyleCop and Resharper)
  • Post-compile .dll checking (FxCop and VS Code Analysis)

3rd party style enforcement

  • Advantages
    1. Easy to set up
    2. Can guarantee easily readable code
  • Disadvantages
    1. Lack of customisation
    2. Rigidness of rule set

Using code reviews

  • Advantages
    1. Useful for detecting bugs and reviewing code style simultaneously
    2. On average detects over 55% of defects
  • Disadvantages
    1. Can be distracted by insigni cant details
    2. Can take large amounts of time (150 lines of code an hour)

Pitfalls of not using a shared coding style

  • Require much more verbose comments to explain methods/classes
  • Much harder to use someone else’s code e.g. when they are ill or even to understand your own code 6 months down the line

These problems will only get worse as the codebase increases in size.

An example of non-styled code:
public int doMagic(int n){
int i=1;
int j=0;
while (i i+=i;
return j;}

An example of styled code:
public int lowestPowerOfTwo(int boundedNumber) {
int multipleOfTwo = 1;
int power = 0;
while (multipleOfTwo < boundedNumber) {
multipleOfTwo *= 2;
return power;

This post is part of our team knowledge share presentations. To see a complete list of these sessions, please take a look at our knowledge sharing page.