Skip to main content
Clean Code 60 XP · 6 min

Selectors & Intent

Boolean and enum selector arguments obscure intent — split them into focused, well-named functions.

Showing
Ad (728×90)

Boolean & Enum Selector Arguments

G15: Selector arguments are flags that choose a path through a function. They're a sign that the function does more than one thing. When you call render(data, true), does true mean verbose? cached? compressed? The reader must dive into the implementation to know. The solution is to split the function: renderVerbose(data) and renderCompact(data) are each immediately understandable.

Obscured Intent

G16: Code should be expressive at the point it is read, not only at the point it is written. Magic numbers like 86400, cryptic algorithm names, and single-letter variables all obscure intent. A reader should understand what a line does without needing to trace its history. Name constants, break complex expressions into named steps, and choose verbs that describe the action precisely.

Code Challenge

Split the calculate_price function into two clearly named functions.

Key takeaway

A selector argument is a confession that a function does two things. The fix is always to split it.

Done with this lesson?

Mark it complete to earn XP and track your progress.