[prev in list] [next in list] [prev in thread] [next in thread] 

List:       webkit-dev
Subject:    Re: [webkit-dev] Using C++ constant local variables in	 WebKit
From:       Darin Adler <darin () apple ! com>
Date:       2011-11-30 2:19:07
Message-ID: 4FBD9A53-272D-46DE-B823-518838897C99 () apple ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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 =93documents the fact that the variable=92s value is not =
changed=94. I think it=92s overstating things to say it =93documents =
use=94.

>   - 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=92t plan on changing it.

>   - May help compiler optimize code.  (We weren't sure whether modern =
compilers do this on their own or not.)

Doesn=92t.

> * Cons
>   - Darin Adler doesn't ever recall fixing a bug in WebKit where a =
constant pointer would have helped.

While true, not really a =93con=94; just weakens the =93pro=94 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=92m not strongly opposed to using const more, but I am mildly opposed =
to it.

-- Darin=

[Attachment #5 (text/html)]

<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; "><div><div>On Nov 28, 2011, at 1:38 PM, David \
Kilzer wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div \
style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: \
after-white-space; ">In a discussion on&nbsp;<a \
href="https://bugs.webkit.org/show_bug.cgi?id=71921">Bug&nbsp;71921</a>, Antti, Darin \
Adler and I started a discussion about using C++ constant pointers in WebKit. \
&nbsp;Does the WebKit community have a consensus opinion on the \
matter?</div></blockquote><div><br></div><div>I thought we were discussing local \
variables in general, not pointer-typed ones specifically.</div><br><blockquote \
type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; "><div>* Pros</div><div>&nbsp; - Documents use \
of variable.</div></div></blockquote><div><br></div><div>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”.</div><br><blockquote type="cite"><div style="word-wrap: \
break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; \
"><div>&nbsp; - Prevents misuse of variable in a later patch (by a different author) \
through enforcement of \
const-ness.</div></div></blockquote><div><br></div><div>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.</div><br><blockquote \
type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; "><div>&nbsp; - May help compiler optimize \
code. &nbsp;(We weren't sure whether modern compilers do this on their own or \
not.)</div></div></blockquote><div><br></div><div>Doesn’t.</div><br><blockquote \
type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; "><div>* Cons</div><div><div>&nbsp; - Darin \
Adler doesn't ever recall fixing a bug in WebKit where a constant pointer would have \
helped.</div></div></div></blockquote><div><br></div><div>While true, not really a \
“con”; just weakens the “pro” argument above that this prevents \
misuse.</div><br><blockquote type="cite"><div style="word-wrap: break-word; \
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>&nbsp; - \
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;).</div></div></blockquote><div><br></div>Not sure this is a con. Just \
stating what the C++ syntax.<br><br></div><div><div>This is the con I am aware \
of:</div><div><br></div><div>&nbsp; - Less brief than omitting \
const.</div><div><br></div><div>I’m not strongly opposed to using const more, but I \
am mildly opposed to it.</div><div><br></div><div>-- Darin</div></div></body></html>



_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic