DEV Community

Mohcin Bounouara
Mohcin Bounouara

Posted on

About code smells

In software engineering field you are probably heard about “Code Smell” before right?, the name comes from Martin Fowler and Kent Beck. So let me explain a little about this concept.
What is and for what code smell?

Code smell in software engineering point on sick code in the deep system of an software, simply is the problems that actually exist in the system but It doesn’t prevent the software from completing its tasks.
Smells are the structures in the code that not respect the fundamental design principles and negatively impact design system quality. So it’s not “BUGS”.

A code smell is a surface indication that usually corresponds to a deeper problem in the system.
— Martin Fowler

For what?

Software engineers use code smells to analyze the existing code using Unit Test and Testing Life Cycle test of the software, after finding the code smells who need of more refactoring.

Code smell: common examples

  • Long methods: Most developers think the complex methods gives them the great image, but NO, do it simple and do it short. Long methods make code hard to maintain and debug.
  • Duplicate Code: don’t repeat yourself!
  • Lazy Class: Remember that lazy classes do the work, but in the future it’s hard to fix in bug cases.
  • Dead Code: Delete it don’t just comment it or let it without doing anything. Make it clean.

Code smell tools

If we take PHP as a use case, we will found that there is a lot of tools using to do that work, some of them that listed next:

And I will come with a practical example of code smell when I have time.

Code smells can be in any system written by programmers, even experienced, so try to use code smells tools to detect the smells and try to refactoring it.

Note: This post is originally posted on my personal blog

Latest comments (0)