Why this matters
Declaring variables far from their usage reduces clarity and makes it harder to track their purpose, leading to maintainability issues.
Ensure that variables are declared as close as possible to their first use to improve readability.
Declaring variables far from their usage reduces clarity and makes it harder to track their purpose, leading to maintainability issues.
Side-by-side examples engineers can pattern-match during review.
int result;
// Many lines of code
result = computeResult();int result = computeResult();int result;
// Many lines of code
result = computeResult();int result = computeResult();From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.