[webkit-dev] Pattern for singleton classes instance getters

Gavin Barraclough barraclough at apple.com
Wed Jan 28 20:13:08 PST 2015


Gotta say, ‘singleton’ seems like a really good name for singletons.

G.

> On Jan 28, 2015, at 7:06 PM, Filip Pizlo <fpizlo at apple.com> wrote:
> 
> This is shorter: Class::singleton()
> 
> It's also more consistent with the rest of our style (we usually don't put "get" in getter names). 
> 
> -Filip
> 
>> On Jan 28, 2015, at 6:11 PM, Maciej Stachowiak <mjs at apple.com> wrote:
>> 
>> 
>>> On Jan 28, 2015, at 4:28 PM, Darin Adler <darin at apple.com> wrote:
>>> 
>>> I like the economy of the smaller non-member function name; it seems overly wordy to be constantly stating the class name as well as the nearly meaningless word “shared”. I think the word “shared” is what I like least about the member function approach.
>>> 
>>> It had always thought that we used static member functions for this to replicate the pattern from Objective-C, and it seems more idiomatic modern C++ to use a free function for this kind of thing.
>>> 
>>> Maciej’s point about Class::create() might be enough to convince me to change my view, though; it’s hard to see any reason the same logic wouldn’t apply in that case.
>> 
>> I would also find it acceptable to use free functions for all these cases. Mostly it bugs me for them to be different - the singleton case is rarer, so it seems odd to treat it as especially conciseness-worthy.
>> 
>> Yet another possibility is finding a better name than ‘shared’ for the singleton pattern function, but I don’t have any better ideas. Class::getSingleton() is more explicit but the extra verbosity doesn’t seem helpful to me.
>> 
>> Regards,
>> Maciej
>> 
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev



More information about the webkit-dev mailing list