Code Smells
Why they’re bad & how to fix them
September 2025
CODE SMELL: Middle man 👤👨👤
• Why is it bad?
– Adds no value—just delegates calls.
– Increases coupling across interfaces.
– Gives a false sense of information hiding.
– Shallow methods hint at poor structure.
• How to fix it?
– Remove pass‑through layers with no added logic.
– Keep layering but avoid ‘just forwarding’ layers.
– Combine methods and simplify the class interface.
CODE SMELL: The long parameter list 📏
• Why is it bad?
– Hard to understand and maintain.
– Ordering mistakes easily break calls.
– Flags (boolean/enum) hide intent and paths.
– Optionality becomes messy as lists grow.
• How to fix it?
– Replace many params with one data object.
– Derive values—remove redundant parameters.
– Avoid flag parameters; split variants into functions.
• (Title links to details)
CODE SMELL: Knowledge duplication 📝📝
• Why is it bad?
– Every change requires hunting all copies.
– Duplicates drift and behave inconsistently over time.
– Couples unrelated places to the same changing knowledge.
• How to fix it?
– Extract shared knowledge into helpers/types.
– Reuse them consistently—keep them small and SOLID.
– Do not merge code that represents different knowledge.
CODE SMELL: Primitive obsession 😱
• Why is it bad?
– Poor encapsulation; logic scattered across code.
– Validation and operations get duplicated.
– Easy to forget updates when behavior changes.
• How to fix it?
– Model domain concepts with rich types.
– Avoid type explosion—seek better abstractions.
– Centralize validation and behavior in those types.
CODE SMELL: Speculative generality 🔮
• Why is it bad?
– Unused fields/methods/classes add complexity.
– Over‑engineering wastes time and attention.
– Harder to maintain and onboard.
• How to fix it?
– Remove unused params, overloads, and types.
– Keep structure simple; build for today’s use case.
– Add generality only when real needs emerge.
CODE SMELL: Long method
• Why is it bad?
– Multiple responsibilities tangled together.
– Harder to reason about and to change safely.
– Buried knowledge cannot be reused.
• How to fix it?
– Identify the core purpose; extract the rest.
– Name functions well to convey intent.
– Create small, cohesive helpers.
CODE SMELL: Feature Envy 😋
• Why is it bad?
– Low cohesion leads to high coupling between modules.
– Easy to call things in the wrong order—bug‑prone.
– Boundaries are blurry; responsibilities unclear.
• How to fix it?
– Move the behavior to the data it uses most.
– Redraw boundaries to improve cohesion.
– “Put things together that change together.”
https://blog.vvauban.com/smell

👃🤢 7 CODE SMELL: spot ’em fast, fix ’em faster

  • 1.
    Code Smells Why they’rebad & how to fix them September 2025
  • 2.
    CODE SMELL: Middleman 👤👨👤 • Why is it bad? – Adds no value—just delegates calls. – Increases coupling across interfaces. – Gives a false sense of information hiding. – Shallow methods hint at poor structure. • How to fix it? – Remove pass‑through layers with no added logic. – Keep layering but avoid ‘just forwarding’ layers. – Combine methods and simplify the class interface.
  • 3.
    CODE SMELL: Thelong parameter list 📏 • Why is it bad? – Hard to understand and maintain. – Ordering mistakes easily break calls. – Flags (boolean/enum) hide intent and paths. – Optionality becomes messy as lists grow. • How to fix it? – Replace many params with one data object. – Derive values—remove redundant parameters. – Avoid flag parameters; split variants into functions. • (Title links to details)
  • 4.
    CODE SMELL: Knowledgeduplication 📝📝 • Why is it bad? – Every change requires hunting all copies. – Duplicates drift and behave inconsistently over time. – Couples unrelated places to the same changing knowledge. • How to fix it? – Extract shared knowledge into helpers/types. – Reuse them consistently—keep them small and SOLID. – Do not merge code that represents different knowledge.
  • 5.
    CODE SMELL: Primitiveobsession 😱 • Why is it bad? – Poor encapsulation; logic scattered across code. – Validation and operations get duplicated. – Easy to forget updates when behavior changes. • How to fix it? – Model domain concepts with rich types. – Avoid type explosion—seek better abstractions. – Centralize validation and behavior in those types.
  • 6.
    CODE SMELL: Speculativegenerality 🔮 • Why is it bad? – Unused fields/methods/classes add complexity. – Over‑engineering wastes time and attention. – Harder to maintain and onboard. • How to fix it? – Remove unused params, overloads, and types. – Keep structure simple; build for today’s use case. – Add generality only when real needs emerge.
  • 7.
    CODE SMELL: Longmethod • Why is it bad? – Multiple responsibilities tangled together. – Harder to reason about and to change safely. – Buried knowledge cannot be reused. • How to fix it? – Identify the core purpose; extract the rest. – Name functions well to convey intent. – Create small, cohesive helpers.
  • 8.
    CODE SMELL: FeatureEnvy 😋 • Why is it bad? – Low cohesion leads to high coupling between modules. – Easy to call things in the wrong order—bug‑prone. – Boundaries are blurry; responsibilities unclear. • How to fix it? – Move the behavior to the data it uses most. – Redraw boundaries to improve cohesion. – “Put things together that change together.”
  • 9.