Skip to main content
Clean Code 60 XP · 6 min

Expressiveness & Algorithms

Use explanatory variables, precise names, and a deep understanding of the algorithm to make code speak for itself.

Showing
Ad (728×90)

Explanatory Variables

G19: When a complex expression fills a line, the reader must mentally evaluate it to understand its meaning. Break it into named steps. Each intermediate variable becomes a comment that can't go stale — it is the computation, named. This is especially important for mathematical formulas, regular expressions, and multi-part boolean conditions.

Precise Names & Algorithm Understanding

G20: A function's name is a contract. getUser promises a read with no side effects. If it also logs, caches, and audits, the name is a lie. Use a name that is the complete truth — even if it's longer. G21: Don't stop working on an algorithm when the tests pass. Understand it. Refactor it until you can explain every line. Code you don't fully understand is code you can't safely change.

Code Challenge

Break the dense formula into explanatory named variables.

Key takeaway

Expressive code is not about being clever — it's about being clear. Name every important intermediate result.

Done with this lesson?

Mark it complete to earn XP and track your progress.