<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 <a href="https://bugs.webkit.org/show_bug.cgi?id=71921">Bug 71921</a>, 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?</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>  - 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>  - 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>  - May help compiler optimize code.  (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>  - 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>  - 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>  - 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>