As I stated on the other thread, I'm against using const pointers. However, I see benefits in using const local variables.
On Tue, Nov 29, 2011 at 6:19 PM, Darin Adler <da...@apple.com> wrote: > > 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”. > Well, we can always call some function with a pointer to it, and the callee can const_cast it. Having said that, declaring it explicitly const makes it clear that it's not intended to be used like that. For example, when I was writing a patch for https://bugs.webkit.org/show_bug.cgi?id=69267, I encountered a line: resolver.setPosition(oldEnd); at http://trac.webkit.org/browser/trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp?rev=101180#L1287 It took me a while before I figured out that oldEnd is never modified and I can do some optimizations here. Presumably I still have to manually look for all lines of code that touches oldEnd even if oldEnd was const due to const_cast. However, it would have at least signaled me the intent. > - 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. > Right, but it tells us the intent of the author, and appears to be useful even if the variable started with prefixes like "old", "original", and "previous". - Ryosuke
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev