How to Find the Stinky parts of your Code
The code smells bad. Let’s see how to change the aromas.
TL;DR: A Compilation of bad smells in code.
The code smells badly.
Let's see how to change the aromas.
In this series, we will see several symptoms and situations that make us doubt the quality of our development. We will present possible solutions.
Most of these smells are just hints of something that might be wrong. They are not rigid rules.
Code Smells
Code Smell 02 - Constants and Magic Numbers
Code Smell 03 - Functions Are Too Long
Code Smell 04 - String Abusers
Code Smell 05 - Comment Abusers
Code Smell 06 - Too Clever Programmer
Code Smell 07 - Boolean Variables
Code Smell 08 - Long Chains Of Collaborations
Code Smell 10 - Too Many Arguments
Code Smell 11 - Subclassification for Code Reuse
Code Smell 13 - Empty Constructors
Code Smell 15 - Missed Preconditions
Code Smell 17 - Global Functions
Code Smell 18 - Static Functions
Code Smell 19 - Optional Arguments
Code Smell 20 - Premature Optimization
Code Smell 21 - Anonymous Functions Abusers
Code Smell 23 - Instance Type Checking
Code Smell 24 - Boolean Coercions
Code Smell 25 - Pattern Abusers
Code Smell 26 - Exceptions Polluting
Code Smell 27 - Associative Arrays
Code Smell 29 - Settings / Configs
Code Smell 30 - Mocking Business
Code Smell 31 - Accidental Methods on Business Objects
Code Smell 34 - Too Many Attributes
Code Smell 35 - State as Properties
Code Smell 36 - Switch/case/elseif/else/if statements
Code Smell 37 - Protected Attributes
Code Smell 38 - Abstract Names
Code Smell 41 - Regular Expression Abusers
Code Smell 42 - Warnings/Strict Mode Off
Code Smell 43 - Concrete Classes Subclassified
Code Smell 44 - Magic Corrections
Code Smell 45 - Not Polymorphic
Code Smell 48 - Code Without Standards
Code Smell 51 - Double Negatives
Code Smell 53 - Explicit Iteration
Code Smell 57 - Versioned Functions
Code Smell 59 - Basic / Do Functions
Code Smell 60 - Global Classes
Code Smell 61 - Coupling to Classes
Code Smell 62 - Flag Variables
Code Smell 64 - Inappropriate Intimacy
Code Smell 65 - Variables Named after Types
Code Smell 66 - Shotgun Surgery
Code Smell 69 - Big Bang (JavaScript Ridiculous Castings)
Code Smell 70 - Anemic Model Generators
Code Smell 71 - Magic Floats Disguised as Decimals
Code Smell 73 - Exceptions for Expected Cases
Code Smell 75 - Comments Inside a Method
Code Smell 76 - Generic Assertions
Code Smell 80 - Nested Try/Catch
Code Smell 82 - Tests Violating Encapsulation
Code Smell 83 - Variables Reassignment
Code Smell 84 - Max < Min (Javascript)
Code Smell 86 - Mutable Const Arrays
Code Smell 87 - Inconsistent Parameters Sorting
Code Smell 88 - Lazy Initialization
Code Smell 89 - Math Feature Envy
Code Smell 90 - Implementative Callback Events
Code Smell 91 - Test Asserts without Description
Code Smell 92 - Isolated Subclasses Names
Code Smell 93 - Send me Anything
Code Smell 94 - Too Many imports
Code Smell 95 - Premature Classification
Code Smell 97 - Error Messages Without Empathy
Code Smell 98 - Speling Mistakes
Code Smell 101 - Comparison Against Booleans
Code Smell 103 - Double Encapsulation
Code Smell 105 - Comedian Methods
Code Smell 106 - Production Dependent Code
Code Smell 107 - Variables Reuse
Code Smell 108 - Float Assertions
Code Smell 109 - Automatic Properties
Code Smell 110 - Switches With Defaults
Code Smell 111 - Modifying Collections While Traversing
Code Smell 112 - Testing Private Methods
Code Smell 116 - Variables Declared With 'var'
Code Smell 117 - Unrealistic Data
Code Smell 120 - Sequential IDs
Code Smell 121 - String Validations
Code Smell 122 - Primitive Obsession
Code Smell 123 - Mixed 'What' and 'How'
Code Smell 124 - Divergent Change
Code Smell 125 - 'IS-A' Relationship
Code Smell 126 - Fake Null Object
Code Smell 127 - Mutable Constants
Code Smell 128 - Non-English Coding
Code Smell 129 - Structural Optimizations
Code Smell 131 - Zero Argument Constructor
Code Smell 132 - Exception Try Too Broad
Code Smell 133 - Hardcoded IF Conditions
Code Smell 134 - Specialized Business Collections
Code Smell 135 - Interfaces With just One Realization
Code Smell 136 - Classes With just One Subclass
Code Smell 137 - Inheritance Tree Too Deep
Code Smell 138 - Packages Dependency
Code Smell 139 - Business Code in the User Interface
Code Smell 140 - Short Circuit Evaluation
Code Smell 141 - IEngine , AVehicle, ImplCar
Code Smell 142 - Queries in Constructors
Code Smell 144 - Fungible Objects
Code Smell 145 - Short Circuit Hack
Code Smell 146 - Getter Comments
Code Smell 147 - Too Many Methods
Code Smell 149 - Optional Chaining
Code Smell 150 - Equal Comparison
Code Smell 151 - Commented Code
Code Smell 152 - Logical Comment
Code Smell 153 - Too Long Names
Code Smell 154 - Too Many Variables
Code Smell 155 - Multiple Promises
Code Smell 156 - Implicit Else
Code Smell 158 - Variables not Variable
Code Smell 160 - Invalid Id = 9999
Code Smell 161 - Abstract/Final/Undefined Classes
Code Smell 162 - Too Many Parentheses
Code Smell 163 - Collection in Name
Code Smell 164 - Mixed Indentations
Code Smell 165 - Empty Exception Blocks
Code Smell 166 - Low-Level Errors on User Interface
Code Smell 167 - Hashing Comparison
Code Smell 168 - Undocumented Decisions
Code Smell 169 - Glued Methods
Code Smell 170 - Refactor with Functional Changes
Code Smell 171 - Plural Classes
Code Smell 172 - Default Argument Values Not Last
Code Smell 173 - Broken Windows
Code Smell 174 - Class Name in Attributes
Code Smell 175 - Changes Without Coverage
Code Smell 176 - Changes in Essence
Code Smell 177 - Missing Small Objects
Code Smell 178 - Subsets Violation
Code Smell 180 - BitWise Optimizations
Code Smell 181 - Nested Classes
Code Smell 182 - Over Generalization
Code Smell 183 - Obsolete Comments
Code Smell 184 - Exception Arrow Code
Code Smell 185 - Evil Regular Expressions
Code Smell 186 - Hardcoded Business Conditions
Code Smell 187 - If/Else Backwards
Code Smell 188 - Redundant Parameter Names
Code Smell 189 - Not Sanitized Input
Code Smell 190 - Unnecessary Properties
Code Smell 191 - Misplaced Responsibility
Code Smell 192 - Optional Attributes
Code Smell 193 - Switch Instead of Formula
Code Smell 194 - Missing Interval
Code Smell 195 - Yoda Conditions
Code Smell 196 - Javascript Array Constructors
Code Smell 197 - Gratuitous Context
Code Smell 198 - Hidden Assumptions
Code Smell 199 - Gratuitous Booleans
Code Smell 201 - Nested Ternaries
Code Smell 202 - God Constant Class
Code Smell 203 - Irrelevant Test Information
Code Smell 204 - Tests Depending on Dates
Code Smell 205 - Code in Destructors
Code Smell 206 - Long Ternaries
Code Smell 207 - Dynamic Methods
Code Smell 210 - Dynamic Properties
Code Smell 211 - Tab over Spaces
Code Smell 212 - Elvis Operator
Code Smell 214 - Duplicate Parameter Names
Code Smell 215 - Deserializing Object Vulnerability
Code Smell 216 - Fat Interface
Code Smell 217 - Empty Implementation
Code Smell 218 - Magic Concatenation
Code Smell 219 - Looping from index 0
Code Smell 221 - Missing Break in Switch
Code Smell 222 - Comma Operator
Code Smell 223 - Racial Naming
Code Smell 224 - Deodorant Comments
Code Smell 225 - Pass by Reference
Code Smell 226 - Mixed Priorities
TL;DR: Design and test the software. It is cheaper than the hardware
Code Smell 228 - Multiple Classes per File
TL;DR: Follow the separation of concerns principle and file organization
Code Smell 236 - Unwrapped Lines
Formatting plays a crucial role in creating code that is not only functional but also readable and maintainable. In this article, I will shed light on the code smell associated with neglecting proper line wrapping and explore why it's considered bad practice, too long, isn't it?
Code Smell 236 - Unwrapped Lines
Code Smell 237 - Attribute Definitions
TL;DR: Never focus on implementation. Focus on behavior instead.
Code Smell 241- Referential Transparency Violation
TL;DR: Your functions should be replaceable by the computation result.
Code Smell 249 - Constants as Numbers
TL;DR: Use real-world constants as constantsThanks for reading Clean Code Cookbook! Subscribe for free to receive new posts and support my work.
Code Smell 254 - Mystery Guest
TL;DR: Be explicit when creating tests to ensure clarity and maintainability
Code Smell 255 - Parallel Hierarchies
TL;DR: Parallel hierarchies lead to duplication and tight coupling.
Code Smell 258 - Secrets in Code
TL;DR: Use a secret manager to avoid hardcoding sensitive information.
Code Smell 261 - DigiCert Underscores
TL;DR: Underscore and special characters can lead to validation errors
Code Smell 262 - Not Replaced Constants
TL;DR: Ignoring constant replacement leads to severe security risks.
Code Smell 263 - Squatting
TL;DR: Secure your cloud resources by avoiding predictable naming patterns.
Code Smell 265 - Linguistic Confusion
TL;DR: Naming is hard, don't make it harder with unnecessary accidental complexity.
Code Smell 266 - Collection Aliasing
TL;DR: Use immutable collections to prevent unintended side effects.
Code Smell 267 - Objects Aliasing
TL;DR: Use immutable objects to prevent unexpected changes caused by aliasing.
Code Smell 268 - Ternary Metaprogramming
TL;DR: Avoid using ternary operators for dynamic method calls
Code Smell 269 - Low-Level Addition
TL;DR: Ditch the Loops: Write Cleaner Code with Declarative Style
Code Smell 270 - Boolean APIs
TL;DR: Replace boolean security flags in APIs with separate, more secure endpoints.
Code Smell 271 - The Hollywood Principle
TL;DR: The Hollywood Principle promotes loose coupling by inverting control. High-level components decide when and how to use low-level components.
Code Smell 272 - API Chain
TL;DR: Use primitive steps to verify API behavior instead of direct requests.
Code Smell 274 - Cascaded Returns
TL;DR: Prevent chaining return statements for better code readability and flow.
Code Smell 275 - Missing Test Wrong Path
TL;DR: Ensure you fail the test when no exception is thrown in invalid conditions.
Code Smell 276 - Untested Regular Expressions
TL;DR: Use clear and concise regular expressions, and test them thoroughly.
Code Smell 277 - UPPERCASE Acronyms
TL;DR: Treat acronyms like normal words to improve human readability.
Code Smell 279 - Loop Premature Optimization
TL;DR: Don't optimize loops without a clear need and concrete real-world evidence
Code Smell 280 - Spaghetti Code
This article is dedicated to the late Thomas E. Kurtz, one of BASIC's creators, as it was the first programming language I learned.
Code Smell 283 - Unresolved Meta Tags
TL;DR: Incomplete or null meta tags break functionality and user experience.
Code Smell 285 - Non-Imperative Functions Names
TL;DR: Functions with unclear names hide intent and confuse readers. Use descriptive, action-oriented names.
Code Smell 286 - Overlapping Methods
TL;DR: Avoid using private methods in parent classes with names that child classes can use.
Code Smell 288 - Unthrown Exceptions
TL;DR: Creating a new exception without throwing it leads to silent failures.
Code Smell 291 - Mutable Keys
TL;DR: When you use mutable objects as keys in hashed collections, changing them breaks contracts.
Code Smell 294 - Implicit Return
TL;DR: Overusing implicit returns makes your code harder to read and debug.
Code Smell 295 - String Concatenation
TL;DR: Avoid string concatenation for complex strings, use templates.
Code Smell 296 - Unhappy to the Right
TL;DR: Arrange your code so the main logic flows along the left margin, handling edge cases early with guard clauses.
Code Smell 297 - Syntactic Noise
TL;DR: Too many cryptic symbols make your code hard to understand and maintain.
Code Smell 298 - Microsoft Windows Time Waste
TL;DR: Skipping status reports in conditional branches causes silent delays and race conditions.
Code Smell 299 - Overloaded Test Setup
TL;DR: Bloated setup that's only partially used makes your tests more coupled and harder to understand.
Code Smell 300 - Package Hallucination
TL;DR: Avoid hallucinated or fake packages that can compromise security and stability.
Code Smell 301 - Database as Parameter
TL;DR: Don't mix data access concerns with essential business behavior.
... and many more to come.
Photo by Richard Ecsedi on Unsplash
Smells are certain structures in the code that suggest (sometimes they scream for) the possibility of refactoring
Martin Fowler
Part of the objective of this series of articles is to generate spaces for debate and discussion on software design.
We look forward to your comments and suggestions on this article.
Original Thread on Twitter