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 <[email protected]><mailto:[email protected]> (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
--
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development