Adopt a “review-first” style for complex C code: keep control flow and conditions small, make side effects explicit, and avoid duplication.
Key rules: 1) Split overly long conditionals
if.if blocks.2) Use guard clauses and shared cleanup
3) Prefer explicit branching for special modes
else if with a clear name/comment.4) Extract duplicated “finalization”/side-effect logic
5) Enforce consistent formatting
if/for/while bodies.{} for scan-ability.6) Use named constants instead of magic numbers
Example (splitting long validation):
// Before (hard to read)
if (parseA()!=C_OK || parseB()!=C_OK || parseC()!=C_OK) return;
// After (reviewable)
if (parseA() != C_OK) return;
if (parseB() != C_OK) return;
if (parseC() != C_OK) return;
Example (shared cleanup to reduce indentation):
if (fast_path_ok) {
goto done;
}
// fallback path
done:
cleanup_common();
return;
Applying these consistently makes diffs easier to scan, reduces reviewer cognitive load, and prevents subtle behavioral drift across similar command implementations.
Enter the URL of a public GitHub repository