Originally published on Caffeina

When a group of people starts working on a very large and important project, it is inevitable to encounter different methods of thinking and writing the code. The risk of having the code difficult to maintain is very high. We decided to study (YES, you need to study to improve processes and write clean code) and understand what was the best approach to be used internally to leave the freedom to interpret the code but maintain a clean and maintainable code base.

What is clean code?

Clean code is a consistent style shared by the programming group that simplifies writing, reading, and code maintenance. It is not enough that the code works for accepting a pull request (obviously with the necessary exceptions) but you have to ask yourself before doing the pull request:

  1. have I removed all the ?

    zombie code

  2. Will anyone else be able to understand this code in six months?

  3. Is it necessary a refactoring that I can not do for reasons of time / information and I have to declare it?

In simpler terms, write code that you would be proud to take home and show your mother.

Clean code is self-commenting

How many times have you really commented on your code? Or how many times have you commented on it and then changed it without even remembering to change the comment? the solution is simple and immediate. Write self-commenting code. It is fundamental to give the right name to things.

Example of clean and bad naming code


Another way to automatically comment on the ReactJS code is to declare the types of props used in order to make anyone who uses our component understand which props are necessary to operate and all those used. In addition, using the props-types, warnings will be printed when props don’t match with the declaration,this will help us to understand what we have wrong

Example of how use propTypes