[webkit-dev] Using C++ constant local variables in WebKit

Ryosuke Niwa rniwa at webkit.org
Thu Dec 1 10:54:20 PST 2011


On Thu, Dec 1, 2011 at 10:48 AM, Ojan Vafai <ojan at chromium.org> wrote:

> On Thu, Dec 1, 2011 at 6:49 AM, Antti Koivisto <koivisto at iki.fi> wrote:
>
>> On Thu, Dec 1, 2011 at 4:26 AM, Ojan Vafai <ojan at chromium.org> wrote:
>>
>>> I don't mind using const in some cases, but I share Darin's concern of
>>> littering the code with consts. I'd prefer that
>>>
>> we come up with a fairly conservative guideline about when to use it. I'm
>>> not sure what that would look like. We could start with, what's special
>>> about this case, or string parsing in general that makes using const more
>>> valuable?
>>>
>>
>> Littering the code with anything is bad. Has misuse of consts been a
>> significant practical problem? Perhaps we don't need a specific rule here.
>>
>
> I guess not. My real problem is that I don't have a good sense of cases
> where it makes sense to use const with local variable, so it's hard for me
> to review patches that add it.
>

A good rule of thumb is when a local variable is never assigned of new
value other than initialization, the constness of the variable is hard to
see in the code, and some other code depends on that fact, and ; i.e. there
is an assumption that the variable's value never changes.

- Ryosuke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20111201/f0029c6c/attachment.html>


More information about the webkit-dev mailing list