Clean Code : what are the benefits for your projects and for the developer’s efficiency?

clean-code-developpement-web-logiciel

Have you ever noticed that the older an application is, the longer it takes to fix bugs or add new features? This increase in time means higher costs, either in development - analysis, implementation and testing - and in maintenance. This is called technical debt.

The reason: too often developers stop working when their code works and not when their code is well done.

We wanted to introduce you to the approach used by our teams of developers: Clean Code. This has been brought forward by the software industry for the past 20 years, but is still relatively unknown in some areas.

Clear evidence

Here are some indicators that explain the difficulties encountered with the code of many computer developments.

  • [Comments] The application shows inappropriate comments, incorrect comments, or even pieces of commented code for some obscure reason
  • [Environment] The application requires several complicated steps to be deployed or the tests are complicated to perform.
  • [Functions] Functions have too many arguments, unnecessary parameters or functions that are no longer called.
  • [Code in General] There is duplicated or non-explicit code, checks that are not done, or dead code (never executed).

Rigid, fragile, complex, unnecessarily repetitive, the code of an application is then difficult to evolve.

The Clean Code approach as an answer

Clean Code is undoubtedly the solution to these problems. It is an extremely pragmatic approach that answers the question: "Why do developers get slow? ". This method is based on fundamental pillars such as the writing of automated tests or programming principles such as the 5 SOLID principles, which are intended to produce software architectures that are more understandable, flexible and maintainable.

In Clean Code, we also find the application of a well-known Scout principle: "When I leave a code file, I leave it cleaner than when I arrived in it". Beyond recommending the use of recognised conventions, Clean Code keeps repeating: "Keep it simple and stupid" (simpler is always better). And this applies at all levels:

  • Design rules
  • Naming rules
  • Comments
  • Source code structure
  • Data structure

At first, this approach may seem intimidating because it involves questioning and changing bad practices that have been integrated by teams... For some, it may even seem boring and not add much value. This feeling is due to the fact that it is a set of small rules which, taken separately, do not seem to solve anything.

Yet it really changes the life of an entire team:

  • Code is easier to fix.
  • Maintenance is accelerated or reduced.
  • New features can be added without fear of jeopardising past developments.

Even if you decide to use only part of the Clean Code principles, it can already significantly improve the daily life of developers. And if you take the time to set up automated tests, the peace of mind on non-regression problems is liberating.

In Conclusion

Is Clean Code easy to implement?

No. Like anything new, it is never easy. You have to integrate new concepts, put them into practice and master them. All this cannot be done in a day.

Does Clean Code solve all the problems?

No. However, if a good part of the principles is implemented correctly, developers can focus on the customer's requirements and not on the mistakes of previous developers.

Is Clean Code worth implementing?

Yes, being a developer is a difficult job that used to be reserved for engineers. This is not insignificant: understanding a client's idea and translating it into computer language can be complex. This process can involve a dozen different specialist professions (backend, frontend, infrastructure, security, mobile, testing, etc.).

Clean Code should be considered as a toolbox for developers, regardless of language. This toolbox is the compilation of decades of experience in IT development. It would be a shame to deprive ourselves of it.

 

Blog post written by Benjamin

Web developer at Contraste Digital

 

-------

Sources :

  • https://en.wikipedia.org/wiki/Robert_C._Martin en [FR] et en [EN]

  • Book : "Une histoire de l'industrie du logiciel"