Skip to main content

Sign in to CleanKata

Track your progress, earn XP, and unlock every lesson.

By signing in you agree to our Terms of Use and Privacy Policy.

Clean Code50 XP5 min

Function Heuristics

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

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.

🔧 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: F1: Few args. F2: No output args. F3: No flag args. F4: No dead functions. Four rules, cleaner functions.

✗ Your version

Function Heuristics — CleanKata — CleanKata