[webkit-dev] For your consideration: Naming scheme for fooIfExists/ensureFoo

Darin Adler darin at apple.com
Tue Jun 18 18:38:30 PDT 2013


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();

I like them better. Note also that I think the requiredStyleResolver function should return a reference so nobody is tempted to do null checks. It seems like the C++ community likes the name optional for this concept; isn’t there some kind of std::optional template?

-- Darin


More information about the webkit-dev mailing list