September 19, 2022
September 19, 2022
Code smells are small mistakes in the programming process, which accumulate gradually and become big problems that hinder the product development process.
Having code smells does not mean that the program will not work, it would still give an output, but it may slow down processing, and increase the risk of failure and errors while making the program vulnerable to bugs in the future.
👃 Smelly code contributes to poor code quality and hence increases the technical debt.
Code smells usually indicate bigger problems. But as the name suggests, they are sniffable or quick to spot. Easy, if your nose twitches while looking at the codes, and you are so close to cursing out loud, it is probably a code smell. (just kidding)
Here are some common signs of smelly codes:
Developing your "code nose" against code smells is something that should happen early in your programming career (if it is going to happen at all.)
Code smells can be easily detected with the help of automatic tools, for example, sonarqube.com, deepsource.io, etc. However, code review still remains necessary (and recommended!) since automated tools cannot detect all code smells, for example, design-related issues.
This is why code review is crucial in assisting developers to detect and deal with code smells early on. To perform a thorough code review, developers must be aware of the indicators of a code smell so that they can identify and correct any issues. Once you have detected the code smells, the next step is to refactor your codes.
But keep this in mind, the important thing is not the refactoring – it is learning to recognize the scent of your own code.
Let’s take a look at a code smell and its solution:
This is Temporary Fields Code Smell, this happens when you have a class instance variables only used sometimes and go unused most of the time. This kind of code is hard to understand.
The solution is to transform them into parameters:
👃 If you want more examples of the stinkiest code imaginable, How to Write Unmaintainable Code is a good place to start. Stay tuned for more coding techniques from FABA Technology. Until next time!