What is Code Smell?


I started to study swift and came across a heavily used term called Code Smell from what I could understand at Wikipedia > and on some other sites it is any symptom in the source code that indicates a deeper problem, eg: duplicate code.

By this definition I end up wondering the following thing, Code Smell is not the same thing as #

How can I identify code smell/bad smell in a code?

asked by anonymous 24.11.2015 / 11:46

3 answers


Determining what a code smell is or is not always a subjective judgment, and will always vary according to the programming language, the developer, and the development methodology.

There are tools that detect certain types of code smells, such as:

Java: Checkstyle, PMD and FindBugs.

. Net: ReSharper.

For Php .

Some common Code smells:

Duplicate code : identical or very similar code exists in more than one location.

Long method : a very extensive method, function, or procedure.

Extended class : a class that ended up getting very extensive (God Object).

Feature envy : A class that overrides methods of another class.

Inappropriate Intimacy : A class that has dependency on the implementation details of another class.

Legacy declined : A class that overrides the generic class method so that the generic class contract is not met by the derived class. >

Lazy class : class that does very little.

Artificial Complexity : Forced use of extremely complicated design patterns, where a simple design would suffice.

Excessively long identifiers : in particular, the use of naming conventions to avoid ambiguities, which should be implicit in the software architecture.

24.11.2015 / 11:59

They are not the same thing. Many code smells will follow these principles of DRY, KISS and YAGNI, which are prevalent in software development, but not all will (examples: Excessively short identifiers in>, Constants class ).

But regardless of that. If smelly situations were obvious to everyone, you would not have to compile a list of code smells in the first place. It would suffice to say "always follow principles like DRY, KISS and YAGNI".

As mentioned, there are tools that detect code smells , but the most complete way to know if your code code smells is to get a good list of > code smells (have an example in Robert C. Martin's "Clean Code" book), study them and see if they exist in your code. If all were obvious and you avoided everyone in your code, congratulations! You are very good at applying the principles of DRY, KISS and YAGNI, among others.

Otherwise, you've got a better sense of the code smells and the principles behind them and you'll be aware of smelly code, and you can apply this to your existing code and future codes. This will help you to have more robust code and following good principles.

24.11.2015 / 12:28
Code smell / bad smell, is the term used to show that something in the code does not make sense (lack of cohesion), if this problem is not addressed it will spread, the cost and effort to correct it will increase. Some examples are classes with more than one responsibility and lack of modularization.

24.11.2015 / 12:01