How to get your team to write clean code

The process for changing a habit is simpler if you are working alone compared to if you are a team

If you are one person, learning to write clean code is a matter of reading some stuff (I gave a few pointers in my previous email). But what can you do if you have a team?

The answer depends. Is it a new team? Or is it an existing team with bad habits?

In all cases, code review is a significant part of the answer. Coders should be reviewing each other’s code. This improves the quality of the code greatly—same thing as with scientific papers, when the review is well-intended—and it provides an instrument that can be used to implement policies.

In new teams, things are relatively simple. If the team leader writes clean code and the rest of the people are new in the team, they will naturally be supervised by the team leader at first, and (s)he will help them get used to writing clean code.

If you have an existing team with a bad habit, it’s more difficult. They need to believe in the change. They also need to see that the management invests in this change. For example, changing the habit will initially slow down development, so you can’t just say that from now on we’ll be writing clean code but this month’s every-day-is-a-deadline schedule goes on unchanged. If these requirements are met, a combination of written specifications, improved version control procedures, and training through code reviews can do it.

(If you happen to be in the situation where you want to make such process improvements for your team, this is a service I can offer, so let’s talk about it.)