When you spot the code smell from line 2134

When you spot the code smell from line 2134

Where does that code smell come from? Line 2134.

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.

<aside> 👃 Smelly code contributes to poor code quality and hence increases the technical debt.

</aside>

How to spot code smells

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:

  1. Rigidity: The software is difficult to change. A small change causes a cascade of subsequent changes.

  2. Fragility: Just one single change, and the whole software collapses.

  3. Immobility: Parts of the codes are un-reusable in other projects due to the high risks and large efforts involved.

  4. Unnecessary Complexity: The codes are too complex to maintain.

  5. Duplicated codes: This is the greatest sin in programming, don’t repeat yourself.

  6. Opacity. The code is hard to understand.

    Untitled

How to develop your “code nose”

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.