Updating our coding conventions and coding style for C++11

Vlad Zahorodnii vladzzag at gmail.com
Thu Jan 16 17:29:11 GMT 2020


Hi,

I would like to update our coding conventions
https://community.kde.org/Policies/Library_Code_Policy.

The auto keyword is not mentioned leading to it being a common point of
contention in reviews as we can't point to a reference.

I would like us to copy Qt's policy [1] for consistency:

Optionally, you can use the auto keyword in the following cases. If in
doubt, for example if using auto could make the code less readable, do
not use auto. Keep in mind that code is read much more often than
written.
When it avoids repetition of a type in the same statement.

    auto something = new MyCustomType;
    auto keyEvent = static_cast<QKeyEvent *>(event);
    auto myList = QStringList() << QLatin1String("FooThing") <<
QLatin1String("BarThing");

When assigning iterator types.

    auto it = myList.const_iterator();

In addition to the coding conventions, I would like to update the KDE
Frameworks Coding Style to include a statement about whitespace before
range-based for loop colons.

The common practice used in KDE seems to be:

    for (a<space>:<space>b)

Cheers,
vlad

[1] https://wiki.qt.io/Coding_Conventions#auto_Keyword


More information about the Kde-frameworks-devel mailing list