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

Friedrich W. H. Kossebau kossebau at kde.org
Fri Jan 17 06:14:43 GMT 2020


Am Donnerstag, 16. Januar 2020, 23:27:57 CET schrieb David Faure:
> On jeudi 16 janvier 2020 18:29:11 CET Vlad Zahorodnii wrote:
> > I would like us to copy Qt's policy [1] for consistency:
> OK, please do.

+1, thanks for the initiative, Vlad.

> Kai-Uwe wrote:
> > for "auto" I think we should always annotate it with const, *, and/or &
> > where appropriate:
> > auto *something = new MyCustomType;
> > auto *keyEvent = static_cast<QKeyEvent *>(event);
> 
> Well, the * is completely redundant in those cases, so it doesn't bring
> anything. I'd be tempted to say, let's not require it.
> But then it raises the question of consistency (without a guideline, we'll
> have some places with * and some places without *).

By my own experience so far I would also settle to say, redundant but very 
helpful to human readers who try to understand some unknown code.

So my +1 for requiring explicit pointer & reference & const with auto. This is 
information too often important for understanding the rest of the code to just 
rely on the human to extract that from the variable initialization code, code 
is much faster to read with that info being explicit.

And sometimes it can also help the code writer to be more sure their 
intention/understanding it matched. And after all "const", "*" & "&" are not 
that expensive to type or bloating up the line :)
More, if you always write them, you will not forget to do so where they are 
not redundant.

Cheers
Friedrich




More information about the Kde-frameworks-devel mailing list