DEV Community

Discussion on: How do you ensure your Team's code is consistent?

Collapse
 
espoir profile image
Espoir Murhabazi • Edited

On top of what is already said, I will add :

first make it work, is your code working ? Does it solves a business problem? Is it adding the value to the company?

Since you said about teamwork, all is to about having good coding conventions ..

Every software engineer said writing the right quality code and consistent code is important but few people made a habit out of it. The problem is not knowledge but consistency.

How to make it a habit?

I will grab some concept from James Clear's book Atomic Habits:

Let me explain how to apply the 4 laws of behaviour change in coding :

1.a. Make it easy and Obvious :

  • Use automatic tools , linter, code quality reviewer like CodeClimate

  • Setup a coding style in your IDE and use auto format feature to format your code according to that style

1.b. Make it hard and invisible :

  • Using tools that block pull requests to get merged if they are not following code standards , I used HoundCI before .
    • Use pre-commit hook that block people to commit code that is not linted.
    • Add a rule to your Git tool to stop people from merging their own merge requests and for other team members to not merge a code that is not reviewed .

2.a. Make it attractive :

  • Explain to your team member the benefit of writing good quality code and how it will make them better software engineers .
  • Do the same for business stakeholders , explain them why technical debt is so bad for the product.
  • Encourage team members to contribute to open sources project to see how those projects are consistent in structure and quality.

2.b. Make it unattractive :

Explain also why it's so bad to write poor quality of code and inconsistent code, and explain how it can lead to some bugs in the future.

3.a Make it satisfying :

What is rewarded is repeated!

  • Use code coverage and congratulate people every time they merge a code that has 100 % of code coverage.
  • Rewards everyone who follow the code conventions in your team :
  • Rewards team members for their open source contributions.

3.b. Make it unsatisfying :

What is punished is avoided!

  • Setup a punishment for people who deliberately follow bad coding practice and violate the team rules