<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div>
<div style="font-family: Calibri,sans-serif; font-size: 11pt;">&quot;Class::unique()&quot; is one of the known names for singletons<br>
<br>
Yong Li</div>
</div>
<div dir="ltr">
<hr>
<span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From:
</span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:mjs@apple.com">Maciej Stachowiak</a></span><br>
<span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent:
</span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎1/‎28/‎2015 9:11 PM</span><br>
<span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To:
</span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:darin@apple.com">Darin Adler</a></span><br>
<span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc:
</span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:webkit-dev@lists.webkit.org">WebKit Development</a></span><br>
<span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject:
</span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [webkit-dev] Pattern for singleton classes instance getters</span><br>
<br>
</div>
<div class="BodyFragment">
<div class="PlainText"><br>
&gt; On Jan 28, 2015, at 4:28 PM, Darin Adler &lt;darin@apple.com&gt; wrote:<br>
&gt; <br>
&gt; 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.<br>
&gt; <br>
&gt; 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&#43;&#43; to use a free function for this kind of thing.<br>
&gt; <br>
&gt; 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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Regards,<br>
Maciej<br>
<br>
_______________________________________________<br>
webkit-dev mailing list<br>
webkit-dev@lists.webkit.org<br>
<a href="https://lists.webkit.org/mailman/listinfo/webkit-dev">https://lists.webkit.org/mailman/listinfo/webkit-dev</a><br>
</div>
</div>
</body>
</html>