[webkit-dev] Do we have a style preference about const member functions?

Peter Kasting pkasting at chromium.org
Tue May 31 11:06:36 PDT 2011


On Tue, May 31, 2011 at 11:00 AM, Maciej Stachowiak <mjs at apple.com> wrote:

> I agree that const should be used for "logical constness". The rule should
> not be merely "doesn't alter any data members of this object" but rather
> "does not alter observable state of this object or vend any type of pointer
> or reference by which observable state of this object could be altered".
>

Precisely!

Because this is subtle, and can't be completely checked by a compiler,
people can often get it wrong.  Used correctly, though, const is a powerful
tool for enforcing correct API usage, allowing optimizations, and informing
readers of a class' contract and functionality.  Reviewers should understand
and consider these sorts of details.

PK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110531/995608d0/attachment.html>


More information about the webkit-dev mailing list