[webkit-dev] For your consideration: Naming scheme for fooIfExists/ensureFoo
Ryosuke Niwa
rniwa at webkit.org
Tue Jun 18 19:05:25 PDT 2013
On Tue, Jun 18, 2013 at 6:38 PM, Darin Adler <darin at apple.com> wrote:
> Lets bike shed!
>
> For some time, functions with names like fooIfExists and ensureFoo have
> been bothering me. I find both names kind of opaque and unpleasant. Here’s
> an example:
>
> StyleResolver* styleResolverIfExists();
> StyleResolver* ensureStyleResolver()
>
> What do you think of these names instead?
>
> StyleResolver* optionalStyleResolver();
> StyleResolver& requiredStyleResolver();
>
requiredStyleResolver sounds as if it's a special (required) type of a
style resolver as opposed to the caller requiring it. Why don't we call it
requireStyleResolver() instead?
Note also that I think the requiredStyleResolver function should return a
> reference so nobody is tempted to do null checks.
Sounds like a great idea.
On Tue, Jun 18, 2013 at 7:03 PM, Emil A Eklund <eae at chromium.org> wrote:
> On Tue, Jun 18, 2013 at 6:38 PM, Darin Adler <darin at apple.com> wrote:
> > What do you think of these names instead?
> >
> > StyleResolver* optionalStyleResolver();
> > StyleResolver& requiredStyleResolver();
>
> +1, much clearer and the pointer vs reference makes it even more so.
> Perhaps enough so that the required prefix could be dropped:
>
> StyleResolver* optionalStyleResolver();
> StyleResolver& styleResolver();
I think it's important to communicate the runtime cost of ensuring the
existence of the object.
- R. Niwa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20130618/1799356c/attachment.html>
More information about the webkit-dev
mailing list