Skip to content

Instantly share code, notes, and snippets.

@jazlopez
Last active August 22, 2022 09:29
Show Gist options
  • Select an option

  • Save jazlopez/849e8f056a74f3bd7276900d92cb2511 to your computer and use it in GitHub Desktop.

Select an option

Save jazlopez/849e8f056a74f3bd7276900d92cb2511 to your computer and use it in GitHub Desktop.
Overview of Fowler’s smells and the levels they pertain to

Overview of Fowler’s smells and the levels they pertain to


Code smell Explanation Level
Long method A method should not consist of many lines of code performing different calculations. Method level
Long parameter list A method should not have many parameters. Method level
Switch statements Code should not contain large switch statements; polymorphism could be used to ease the code. Method level
Primitive obsession Avoid the overuse of primitive types in a class. Class level
Incomplete library class Methods should not be added to random classes instead of to a library class. Class level
Large class A class should not have too many methods and fields, making it unclear what abstraction the class provides. Class level
Lazy class A class should not be doing too little to justify its existence. Class level
Data class Classes should not contain only data; they should contain methods as well. Class level
Temporary field Classes should not contain unnecessary temporary fields. Class level
Data clumps Data often used in combination belongs together and should be stored together in a class or structure. Class level
Divergent change Generally, code changes should be local, preferably to one class. If you have to make many different changes in different places, that indicates a poor structure in the code. Codebase level
Feature envy When many methods in class A are referenced from class B they belong in B and should be moved there. Codebase level
Inappropriate intimacy Classes should not be connected to other classes extensively. Codebase level
Duplicated code or code clones The same or very similar code should not occur in multiple different places in a codebase. Codebase level
Comments Comments should describe why the code is there, not what it does. odebase level
Message chains Avoid message chains that are long chains of message calls, where methods call methods call methods, and so on. Codebase level
Middle man If a class is delegating too much responsibility, should it exist? Codebase level
Parallel inheritance When you make a subclass of one class, you need to makea subclass of another. This indicates that the functionality of both classes might belong in one class. Codebase level
Refused bequest When classes inherit behavior they do not use, the inheritance might not be necessary. Codebase level
Shotgun surgery Generally, code changes should be local to one class. If you have to make many different changes in different places, that indicates a poor structure in the code. Codebase level
Speculative generality Do not add code to a codebase “just in case”; only add features that are needed. Codebase level
Glossary:
METHOD-LEVEL CODE SMELLS

An example of a code smell that pertains to an individual method is a method that consists of many lines of code and has a lot of functionality. Another code smell occurs when a method has a large number of many parameters.

CLASS-LEVEL CODE SMELLS

In addition to code smells that exist at the method level, there are code smells at the class level. An example is a large class, sometimes also called a God class. A large class is a class that has so much functionality that it is no longer a meaningful abstraction. Similarly, a class can have too few methods and fields to be a meaningful abstraction.

CODEBASE-LEVEL CODE SMELLS

When a codebase contains very similar code in different places, the codebase has the duplicated code smell, also called code clones.

source:

The Programmers Brain Part 3 On Writting Better Code Table 9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment