foundation
Function size
Keep functions small enough to explain one intent, but avoid extraction that hides the flow or creates meaningless wrappers.
Functions should fit one level of abstraction and one clear intent—often 10–30 lines as a heuristic, not a law. Extract when blocks need names or reuse; avoid extraction that scatters linear flow across meaningless one-line wrappers.
If you need comments to separate sections, consider functions named after those sections.
On interviews: refactor a 60-line function into orchestrator plus helpers without losing readability.
Common pitfalls: god functions doing IO and business rules, over-extraction obscuring story, and premature micro-functions harming stack traces.
The trade-off is local readability versus jump-to-definition navigation.
Checklist:
- One intent per function.
- Match abstraction level within a function.
- Extract named steps, not every two lines.