04 Nov 2021

In my first years as a front-end developer, I was part of a team of developers where the Tech Leads were very worried about "cleaning" the code.

In retrospect, I understand what they were asking of me: that my code needed to be very descriptive so that anyone could understand it. If someone reviewed my code, they should realize quickly and easily how we solved the user stories of the client. The end result would be readable and maintainable code.

And how could we achieve that? Well, it's not all that complicated and the Tech Leads were right, we needed clean code. Since then I have had mentors that helped me a lot, and they helped uncover a desire for continuous learning that continues to this day using certain courses and books. And, the concept of writing clean code has stuck with me.

In this post, I focus on some points that we need to have in mind when we write clean code, focusing on JavaScript.

1. Use descriptive names

Make the names of the variables and the names of the functions must be as descriptive as they can be. For example, suppose you want to make some references to the character and last name. In that case, you might use a variable that calls "namePhysician" and "lastNamePhysician" instead of using "name." Even worse if you use "n." Why? Because with that syntax, anybody can understand what value the variable contains.

And what about a function? Well, the name of a function must start with a verb. For example, if I have a function that returns the physician's name, I can create a function that calls "getPhysicianName" instead of using a function that only calls "name."