[webkit-dev] On returning mutable pointers from const methods

Antti Koivisto koivisto at iki.fi
Thu Oct 25 07:15:53 PDT 2012


On Thu, Oct 25, 2012 at 1:48 PM, Andreas Kling <kling at webkit.org> wrote:

>
> So, I propose that we allow only these two signature formats for raw
> pointers:
>
> - const Foo* foo() const;
> - Foo* foo();
>

I think this would be an excellent rule to adopt for new code. The
mutable/immutable state pattern is a powerful way to optimize data
structures that are rarely mutated. Correct use of const through the code
makes using it much easier and safer. With adaption of PassRef/OwnPtr I
can't think of any correct uses for Foo* foo() const.


   antti

Moreover, for methods that return references to objects where call sites
> are expected to take a strong reference, we should really be using
> PassRefPtr<Foo> as the return type.
>
> Thoughts? Objections? Am I missing something?
>
> -Kling
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20121025/0ec7cbba/attachment.html>


More information about the webkit-dev mailing list