Selectors & Intent
Boolean and enum selector arguments obscure intent — split them into focused, well-named functions.
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.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: G15: If a boolean arg changes what the function does, split it into two functions. G16: Replace magic values with named constants.
✗ Your version