<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I am working on a software in which singleton has been used in tons of places to "simplify" design.</div><div class="">Today, some parts of the code base are pretty impossible to test, and hard to evolve since all parts have strong links with other parts.</div><div class=""><br class=""></div><div class="">So I completely agree with Jordan : the singleton is a template that should be used in very specific cases and with care. I think making it a first citizen of the language by dedicating a keyword to it will not push good code design.</div><div class=""><br class=""></div><div class="">Jerome</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 12 déc. 2015 à 01:09, Riley Avron via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">-1. Agreed for all of Jordan's reasons.</div><div class="gmail_extra" style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><br class=""><div class="">Riley</div></div></div></div><br class=""><div class="gmail_quote">On 11 December 2015 at 14:55, Jordan Rose via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class="">-1. Enforced singletons lead to code that can't be unit-tested. Local types are occasionally convenient and they can't be unit-tested either, but spending one extra line to name the thing isn't going to hurt. You also can't pick an initializer here (at least not in this version).</div><div class=""><br class=""></div><div class="">IMHO, this just adds "another kind of thing" just to make code shorter, and "shorter" is not the right goal for Swift.</div><div class=""><br class=""></div><div class="">Best,</div><div class="">Jordan</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On Dec 11, 2015, at 14:07, Marc Knaup via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class="">Hey guys,<div class=""><br class=""></div><div class="">I am working on a proposal which touches (and could even partially depend on) another interesting concept which I think would be a great addition for Swift.</div><div class=""><br class=""></div><div class="">Object declarations could be a way to declare a class or struct with exactly one instance. They are perfect for singletons, anonymous subclasses and to anonymously implement a protocol.</div><div class=""><br class=""></div><div class="">Here some examples how it could look like:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">// singleton</font></div><div class=""><font face="monospace, monospace" class="">object GlobalResource {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>func doSomething() { … }</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">let resource = GlobalResource</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">// could all be the same</font></div><div class=""><font face="monospace, monospace" class="">resource.doSomething()</font></div><div class=""><font face="monospace, monospace" class="">GlobalResource.doSomething()</font></div><div class=""><font face="monospace, monospace" class="">GlobalResource.Type.doSomething()</font></div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">// anonymous subclass</font></div><div class=""><font face="monospace, monospace" class="">class ViewController: UIViewController {</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>override func loadView() {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>view = object: UIView {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>// configure view</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>}</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>}</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">// anonymous protocol implementation</font></div><div class=""><font face="monospace, monospace" class="">protocol TapHandler {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>func handleTap()</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">view.tapHandler = object: TapHandler {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>func handleTap() {</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>// …</font></div><div class=""><font face="monospace, monospace" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>}</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><br class=""></div><div class="">Kotlin is an example for a a modern language which uses this concept:</div><div class=""><a href="https://kotlinlang.org/docs/reference/object-declarations.html" target="_blank" class="">https://kotlinlang.org/docs/reference/object-declarations.html</a><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">What do you think about such an addition?</div></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSAWVUCgq6j2gIMHLwUtsMvkh6zS-2F42OEDmC-2FuP8IhnJLSUcx5onHlpzOIn-2Frg3W6-2FKCm-2BXK-2FwGfUgVX09VHJVmk0TZUSq1TJuaeeSv-2FaBPGDu-2B53-2Bqq59Y9-2B5QQfYQCKUU-2Ft-2FjzKmkw6Hagd6EvybiQEVi8zW1ZX8PM26dnKJqSktSHIVAl3j0WqiS-2BX-2BGJKow-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________<span class=""><br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></blockquote></div><br class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=sIRoRT5zo00ToqQvAg-2Bayulo6Lqyk-2F0O-2BuwWmVBacYRM9IAEoCVT8fj4z6r5TdTNCGUPUTc-2BwkxC1v5U4cBeLuLkGmPlIeDaF5GmAt-2B1vDLjhCzVVIkzzMWobL1pXqUyLBCD4bldPBcs8fktUBi-2FAI4ki4v619-2F5y3h6fOWfLePc7MVtCsPz7cYlWDvP-2Bgs7Pl3lgxvpZ5Km8acVRvaG5iReIx3u7zw4JMfduUhsHcA-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class=""></blockquote></div><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZfNDJ3c1KY40DpRPxaBpmw0PAd1TZW0h3lqFWlwcZNWu8FFE3i1tSoM-2BXNGVk-2F0gVUVHoaG39ClYewm-2FOarxt694h0yfhfcHPSa32mUubyo5Eiujypz6DcSvN8pdYv1DsgxY-2FhiyNqxC-2BucIrVaA1s-2FpiiZVWTRJxqGbXGwXmkoUSeWKrBoKgb12c7O3IaOTIAkYZF3-2BwijDNthRXRtvNqGKcdgg8GBYx1F-2FoYbYuI4-3D" alt="" width="1" height="1" border="0" style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: TimesNewRomanPSMT; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>