<html><body><div>That's a good argument, but I'm not convinced: not only do I have to define additional protocols ("DefaultXXX") but in the worst case I have to do this for each method declared in my protocol (which makes naming these default protocols even worse, because XXX now has to represent the method), i.e.<br></div><div><br data-mce-bogus="1"></div><div>protocol BooType {<br data-mce-bogus="1"></div><div>&nbsp;&nbsp; func someBoo()<br></div><div>&nbsp;&nbsp; func anotherBoo()<br></div><div>&nbsp;&nbsp; func yetAnotherBoo()<br></div><div>}<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>when given:<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><span class="body-text-content">struct Foo {<br> &nbsp;&nbsp;&nbsp;func someBoo() { print("foo boo") }<br>}<br>struct Bar {</span></div><div><span class="body-text-content">&nbsp;&nbsp;&nbsp;func anotherBoo() { print("bar boo") }</span></div><div><span class="body-text-content"> }<br>struct Baz { </span></div><div><span class="body-text-content">&nbsp;&nbsp;&nbsp;func anotherBoo() { print("baz boo") }</span></div><div><span class="body-text-content">}</span></div><div><span class="body-text-content"><br data-mce-bogus="1"></span></div><div><span class="body-text-content">I would have to define all of the following:<br data-mce-bogus="1"></span></div><div><br data-mce-bogus="1"></div><div>protocol DefaultBooTypeSomeBoo : BooType { }<br data-mce-bogus="1"></div><div>extension DefaultBooTypeSomeBoo {<br data-mce-bogus="1"></div><div>&nbsp;&nbsp;&nbsp;func someBoo() { print("some boo") }<br></div><div>}<br data-mce-bogus="1"></div><div><div>protocol DefaultBooTypeAnotherBoo : BooType { }<br data-mce-bogus="1"></div><div>extension DefaultBooTypeAnotherBoo {<br data-mce-bogus="1"></div><div>&nbsp;&nbsp;&nbsp;func anotherBoo() { print("another boo") }<br></div><div>}<br data-mce-bogus="1"></div><div><div>protocol DefaultBooTypeYetAnotherBoo : BooType { }<br data-mce-bogus="1"></div><div>extension DefaultBooTypeYetAnotherBoo {<br data-mce-bogus="1"></div><div>&nbsp;&nbsp;&nbsp;func yetAnotherBoo() { print("yet another boo") }<br></div><div>}<br data-mce-bogus="1"></div><div><br></div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div><div>Even worse: if the protocol itself is not under my control I cannot even do this (not even for the simple case you demonstrated)!<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>-Thorsten<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br>Am 06. Januar 2016 um 09:36 schrieb Xiaodi Wu &lt;xiaodi.wu@gmail.com&gt;:<br><br><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span class="body-text-content"><blockquote type="cite" class="quoted-plain-text">The pattern might exist for some existing classes or structs but it might still be useful for new classes or even for some existing ones to provide a default implementation.</blockquote><br>I agree. It could be very useful in certain circumstances, and I agree<br>that any proposal that made this no longer possible would be a<br>non-starter. I had to think about this point for a bit; I hope I can<br>convince you that it would remain possible if overriding methods had<br>to use a keyword. The way it would be done would be valid code today,<br>and I think after some reflection that it's a superior way of doing<br>things even in today's Swift syntax because it's more explicit about<br>what's going on.<br><br>Example:<br>Given three existing struct types--<br><br>struct Foo {<br> func boo() { print("foo boo") }<br>}<br>struct Bar { }<br>struct Baz { }<br><br>We wish to formalize after the fact, giving each type a method boo()<br>with a default implementation. Currently, this is valid Swift code--<br><br>protocol BooType {<br> func boo()<br>}<br>extension BooType {<br> func boo() { print("default boo") }<br>}<br>extension Foo: BooType { }<br>extension Bar: BooType { }<br>extension Baz: BooType { }<br><br>As you point out rightly, this would be invalid if we had to write<br>"override func boo()" in the body of struct Foo. However, this is<br>valid Swift code both in today's syntax and if my proposal were to be<br>implemented, and it is only one line longer--<br><br>protocol BooType {<br> func boo()<br>}<br>protocol DefaultBooType: BooType { }<br>extension DefaultBooType {<br> func boo() { print("default boo") }<br>}<br>extension Foo: BooType { }<br>extension Bar: DefaultBooType { }<br>extension Baz: DefaultBooType { }<br><br>I'd like to promote the second option as being superior even in<br>today's syntax. It is immediately clear to the reader that Foo().boo()<br>invokes a different method than Bar().boo(), even if the reader does<br>not have access to the original code for structs Foo, Bar, and Baz.<br>Suppose those structs were supplied in a third-party library that's<br>not well documented. It's plausible that a non-expert coder could try<br>to formalize after the fact and write an extension BooType<br>implementing boo() unaware that there is an overriding method in Foo.<br>In today's Swift syntax, the code would compile and behave subtly<br>differently from the author's expectations; as proposed, that code<br>would lead to a compile-time error. However, an expert coder who<br>intended to supply a default function but invoke any overriding<br>methods could write code that is almost as succinct but also<br>self-documenting, and in fact could do so today.<br><br><br>On Wed, Jan 6, 2016 at 12:45 AM, Thorsten Seitz &lt;tseitz42@icloud.com&gt; wrote:<br><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">&gt; Am 06.01.2016 um 06:23 schrieb Xiaodi Wu via swift-evolution &lt;swift-evolution@swift.org&gt;:</blockquote><blockquote type="cite" class="quoted-plain-text">&gt;</blockquote><blockquote type="cite" class="quoted-plain-text">&gt; It would remain very much possible to formalize an existing pattern because, in the case of your example (unless I'm misunderstanding?), you are not also providing a default implementation of the "min" and "max" getters, and the IntXX structs would have nothing to override. Indeed, you'd hardly be formalizing an existing pattern if you had to supply de novo implementations!</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">The pattern might exist for some existing classes or structs but it might still be useful for new classes or even for some existing ones to provide a default implementation.</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">-Thorsten</blockquote></span></div></div></blockquote></div></div></body></html>