[webkit-dev] Using C++ constant local variables in WebKit
Darin Adler
darin at apple.com
Tue Nov 29 18:19:07 PST 2011
On Nov 28, 2011, at 1:38 PM, David Kilzer wrote:
> In a discussion on Bug 71921, Antti, Darin Adler and I started a discussion about using C++ constant pointers in WebKit. Does the WebKit community have a consensus opinion on the matter?
I thought we were discussing local variables in general, not pointer-typed ones specifically.
> * Pros
> - Documents use of variable.
I would say “documents the fact that the variable’s value is not changed”. I think it’s overstating things to say it “documents use”.
> - Prevents misuse of variable in a later patch (by a different author) through enforcement of const-ness.
Prevents one specific type of misuse: Setting the variable to another value. And that may not be misuse despite the fact that the original author didn’t plan on changing it.
> - May help compiler optimize code. (We weren't sure whether modern compilers do this on their own or not.)
Doesn’t.
> * Cons
> - Darin Adler doesn't ever recall fixing a bug in WebKit where a constant pointer would have helped.
While true, not really a “con”; just weakens the “pro” argument above that this prevents misuse.
> - Slightly more verbose syntax for constant pointers to a constant string (const char * const pointer;) or even a constant pointer to a mutable string (char * const pointer;).
Not sure this is a con. Just stating what the C++ syntax.
This is the con I am aware of:
- Less brief than omitting const.
I’m not strongly opposed to using const more, but I am mildly opposed to it.
-- Darin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20111129/d7722187/attachment.html>
More information about the webkit-dev
mailing list