Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8252576

HotSpot Style Guide has brace exception for simple one line statements

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 16
    • 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.

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

              Created:
              Updated: