← → or space · progress saves for Continue on the roadmap
Goal
Keep each function easy to read top-to-bottom and cheap to test.
Size
- If you scroll a long way to see the end, consider extracting steps with names (
_validate,_normalize,_persist). - “Small” is not a character count; it is one clear job per function.
Early returns
- Handle guard clauses first: null, empty input, feature flags, permission checks.
- After guards, the “happy path” stays at one indentation level.
Nesting
- Deep
ifinsideifinsideforis a signal to extract or invert conditions.
Practice tasks
- Take one function with nested
if/elseand rewrite with early returns only. - Extract the body of a
tryblock intoFuture<void> performWork()sotry/catchstays thin at the boundary. - Add a private helper whose name reads like a sentence in the caller.