[Development] Braces (was Re: Resolving coding style contentions)

Alberto Mardegan mardy at users.sourceforge.net
Fri Dec 21 07:59:34 CET 2018


Hi all!
  Speaking of coding style again, I haven't found any indication in the
coding guidelines about brace vs parentheses in initializations.

There are a few cases where they can be used (and I might even be
forgetting some):

1) Constructors:
       MyClass(): var(0) {}
   vs
       MyClass(): var { 0 } {}

2) Member initializations:
       class MyClass
       {
           int m_count = 3;
   vs
           int m_count { 3 };

3) Variable initialization
       bool ok = false;
   vs
       bool ok { false };

4) Constructor invocations:
       auto *item = new Item("name", parent);
   vs
       auto *item = new Item { "name", parent };

   or

       QString message(QStringLiteral("text"));
   vs
       QString message { QStringLiteral("text") };
   I guess this is not an option:
       QString message { QStringLiteral { "text" } };


I'm not mentioning the cases of struct and list initializers, where of
course braces are the only option. But what is the consensus on the
cases above?
Looking at the Qt code, it seems that variant without braces is always
preferred, but I cannot find it formalized anywhere.

Ciao,
  Alberto

-- 
http://blog.mardy.it - Geek in un lingua international



More information about the Development mailing list