...
Code Block | ||
---|---|---|
| ||
public class Example { private T a; // purpose of a... private T b; // purpose of b... private T[] c; // purpose of c[]... private T d; // purpose of d... public Example(T in){ a = in; b = in; c = (T[]) new Object[10]; d = in; } } |
Exceptions
Quality Tradeoff
Declaration of multiple variables per line can reduce code readability and lead to programmer confusion.
DCL01-EX1: Note that the declaration of a loop counter in a for
statement is in violation of this guideline because the declaration is not on its own line with an explanatory comment about the variable's role. However, declaration of loop indices in for
statements is not only a common idiom but also provides the benefit of restricting the scope of the loop index to the for
loop itself. This is a specific reason to relax this guideline.
...
Code Block | ||
---|---|---|
| ||
public class Example { void function() { int mx = 100; // some max value for (int i = 0; i < mx; ++i ) { /* ... */ } } } |
Risk Assessment
Declaration of multiple variables per line can reduce code readability and lead to programmer confusion.
...
Guideline
...
Severity
...
Likelihood
...
Remediation Cost
...
Priority
...
Level
...
DCL54-JG
...
low
...
unlikely
...
low
...
...
L3
Related Guidelines
C Secure Coding Standard: DCL04-C. Do not declare more than one variable per declaration
...
Section 6.1, "Number Per Line" | |
[ESA 2005] | Rule 9: Put single variable definitions in separate lines. |
[JLS 2005] | |
| |
| |
| |
|
DCL50-JG. Use visually distinct identifiers 01. Declarations and Initialization (DCL) DCL59-JG. Avoid ambiguous overloading of varargs methods