[Development] Suggesting update brace placement following a multi-line if condition

André Somers andre at familiesomers.nl
Fri Jul 17 17:27:23 CEST 2026


Hi,


On 16-07-2026 11:14, Marc Mutz via Development wrote:
> Hi,
>
> The current style guide¹ asks for attached braces on if statements, 
> incl. when the if condition spans multiple lines (#6):
> // Correct if (address.isEmpty() || !isValid() || !codec) { return 
> false; }
> I've been bothered by this for years, since I think this is totally 
> unreadable. In particular, if the last line of the if is on the longer 
> side, the body of the then branch is almost impossible to distinguish 
> from a continuation of the condition.
>
> I would therefore like to propose to allow placing the opening brace 
> on a separate line if the if condition is multi-line:
> // (now also) Correct if (address.isEmpty() || !isValid() || !codec) { 
> return false; }

I agree. I find this more readable. But I would prefer to have logical 
groups of the condition be either broken one per line, or all on the 
same line. So:


  // Correct
  if (address.isEmpty() || !isValid() || !codec) {
      return false;
  }

or


  // (now also) Correct
  if (address.isEmpty()
      || !isValid()
      || !codec)
  {
      return false;
  }

But also this:

  // (now also) Correct
  if ((address.isEmpty() && !isValid())
      || !codec)
  {
      return false;
  }


Cheers,


André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20260717/b75697b3/attachment.htm>


More information about the Development mailing list