| 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 |
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.
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.
When a codebase contains very similar code in different places, the codebase has the duplicated code smell, also called code clones.
The Programmers Brain Part 3 On Writting Better Code Table 9.1