What Is a Code Smell?

A code smell is a surface-level indicator in source code that suggests a deeper problem in the design, without necessarily being a bug itself.

Published October 8, 2026

A code smell is a surface sign in code that often hints at a deeper design problem, such as very long functions, duplicated code or too many parameters. It is not a bug, but a prompt to look closer.

The concept

Common smells: long method, large class, duplicated code, long parameter list, feature envy, magic numbers and deep nesting.

Each smell has standard refactorings: extract method, split class, introduce parameter object.

Smell → fix

long method → extract method
duplicated code → extract shared function
long parameter list → parameter object
magic number → named constant

Practical examples

Long parameter list

createUser(name, email, age, city, zip, phone, newsletter)
// → createUser({ name, email, profile, prefs })

Deep nesting

if (a) { if (b) { if (c) { go() } } }
// → if (!a || !b || !c) return; go()

Duplicated logic

const tax = (p) => p * 0.18   // one place instead of five

Common mistakes

  • Treating every smell as a must-fix.
  • Ignoring smells in hot spots that change often.
  • Fixing smells without tests.

Key takeaways

  • Smells indicate possible design problems.
  • Fix with named refactorings.
  • Prioritise code that changes often.

FAQ

Smell vs bug?

A bug breaks behaviour; a smell makes code harder to maintain.

Can tools find smells?

Linters and SonarQube detect many of them.

More General articles