Skip to main content
Clean Code 50 XP · 5 min

Function Heuristics

Apply the F1–F4 heuristics to keep functions minimal, focused, and side-effect-free.

Showing
Ad (728×90)

F1 & F2 — Arguments

F1: Too Many Arguments — zero is ideal, one is fine, two is acceptable, three requires justification, four or more always needs refactoring. Group related parameters into a data object. F2: Output Arguments — functions should return values, not mutate their arguments. Output args are deeply confusing to callers.

F3 & F4 — Flags and Dead Code

F3: Flag Arguments are a code smell. A boolean parameter signals the function does two things — split it into two honest functions. F4: Dead functions that are never called waste space and create confusion. Delete them — version control keeps history.

Code Challenge

Name the F-heuristic violated before revealing the fix.

Key takeaway

F1: few args. F2: no output args. F3: no flags. F4: no dead code. Four rules that cover most function smells.

Done with this lesson?

Mark it complete to earn XP and track your progress.