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

Marc Mutz marc.mutz at qt.io
Thu Jul 16 11:14:53 CEST 2026


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 have used this in the past weeks here and there, either mentioned in the commit message or silently, and I didn't receive any push-back.

NB: this does _not_ mean that an else should use this format

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

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

¹ https://wiki.qt.io/Qt_Coding_Style#Braces Bullets #1 and #6.

Thanks,
Marc

--
Marc Mutz <marc.mutz at qt.io><mailto:marc.mutz at qt.io> (he/his)
Principal Software Engineer

The Qt Company
Erich-Thilo-Str. 10 12489
Berlin, Germany
www.qt.io<http://www.qt.io>

Geschäftsführer: Mika Pälsi, Juha Varelius, Juha Puputti
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht Charlottenburg,
HRB 144331 B

Public
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20260716/1d1c866b/attachment.htm>


More information about the Development mailing list