HotSpot Style Guide has brace exception for simple one line statements

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 16
    • Component/s: hotspot

      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.

            Assignee:
            Unassigned
            Reporter:
            Kim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: