-
Enhancement
-
Resolution: Unresolved
-
P4
-
16
The Style Guide currently says:
Use One-True-Brace-Style. The opening brace for a function or class
is normally at the end of the line; it is sometimes moved to the
beginning of the next line for emphasis. Substatements are enclosed
in braces, even if there is only a single statement. Extremely
simple one-line statements may drop braces around a substatement.
Why not just skip the last sentence? People interpret extremely simple one-liners differently and this sentence just adds a loop-hole for those that like to write if-statements without braces. This could be considered an extremely simple one-liner:
int append(const E& elem) {
if (this->_len == this->_max) grow(this->_len);
int idx = this->_len++;
this->_data[idx] = elem;
return idx;
}
but some people think we should not be writing code like this anymore.
Use One-True-Brace-Style. The opening brace for a function or class
is normally at the end of the line; it is sometimes moved to the
beginning of the next line for emphasis. Substatements are enclosed
in braces, even if there is only a single statement. Extremely
simple one-line statements may drop braces around a substatement.
Why not just skip the last sentence? People interpret extremely simple one-liners differently and this sentence just adds a loop-hole for those that like to write if-statements without braces. This could be considered an extremely simple one-liner:
int append(const E& elem) {
if (this->_len == this->_max) grow(this->_len);
int idx = this->_len++;
this->_data[idx] = elem;
return idx;
}
but some people think we should not be writing code like this anymore.
- relates to
-
JDK-8252577 HotSpot Style Guide should link to One-True-Brace-Style description
- Resolved