<html><head><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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 20, 2016, at 7:01 PM, Nate Birkholz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I feel like leaving whether and when to call super up to the programmer is a more general solution. In my current codebase, calling super on an inherited method is what i *don't* want, instead overriding the whole method on every child.</div></div></blockquote><div><br class=""></div><div>In cases where it doesn’t matter whether super is called or not that works fine. &nbsp;However, if the superclass is designed in such a way that certain methods must *always* be called if overrides it will lead to bugs when that doesn’t happen. &nbsp;In these cases it would be nice if the compiler could enforce that for us. &nbsp;In cases where you *don’t* want super to be called you would use an annotation like @no_super to make sure that it *isn’t* called by subclasses.</div><div><br class=""></div><div>This comes down to whether we believe expressing and enforcing the intended override semantics in the language is worthwhile or not. &nbsp;I believe it is.</div><div><br class=""></div><div>-Matthew</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Jan 20, 2016 at 4:53 PM, Jesse Squires via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks Matthew and Howard! A lot of good points there.<br class="">
<br class="">
There are certainly a few more possible semantics for overrides than I was initially thinking. It’s not clear to me if the language should support each use case or not. Doing so seems to add unnecessary complexity for (potentially) little gain.<br class="">
<br class="">
I can’t say for sure, but my guess is that the *most common* scenario is: "if a method is overridden, it must call super first". This would also make automatically synthesizing the call to super simpler, which I think is a great idea. Clients then have less of a burden when subclassing.<br class="">
However, as noted, non-void returns complicate this. Also, I agree that re-purposing `required` could be confusing. I’m open to ideas for an alternative keyword.<br class="">
<br class="">
Again, a lot of good ideas/feedback. I’m actually not sure where this leaves us. :) Accounting for all of the possible semantics seems too complex and burdensome, though I think our current state is insufficient. And perhaps accounting for only the simplest scenario, "if a method is overridden, it must call super first", would only further highlight the lack of ability to express the other possible semantics.<br class="">
<br class="">
¯\_(ツ)_/¯&nbsp; I’d love to hear if anyone else has ideas or shares these concerns!<br class="">
<br class="">
Jesse<br class="">
<br class="">
<br class="">
&gt; On Jan 18, 2016, at 11:34 AM, Howard Lovatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Are there other languages worth investigating which have the requires super first/last semantics you note?<br class="">
&gt;&gt;<br class="">
&gt;&gt; I don’t know of any languages that support this.&nbsp; It is not the most common semantic, but when it occurs it seems important enough that it would be better if it could be specified in the language itself and enforced rather than left to documentation.<br class="">
&gt;<br class="">
&gt; BETA has this ability, but it worked rather differently than modern OO languages (which work more like its predecessor Simula). In BETA you can only ever call the top most method, it can then optionally call the immediately overriding method. The syntax BETA uses is `inner(&lt;args&gt;)`. Probably easier with examples (in BETArised Swift):<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; class Base {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; func finalM() { print("finalM") }<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; func mustOverrideM() {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("beforeInner")<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inner()<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("afterInner")<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">
&gt;&nbsp; &nbsp; }<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; class Derived: Base {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; func mustOverrideM() {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("inInner")<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">
&gt;&nbsp; &nbsp; }<br class="">
&gt;<br class="">
&gt; Methods `finalM` and `Derived.mustOverrideM` are automatically final because they do not call inner.<br class="">
&gt;<br class="">
&gt; You can't make an instance of `Base` because method `Base.mustOverrideM` needs to be overridden, i.e. `Base` is automatically abstract.<br class="">
&gt;<br class="">
&gt; If you:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; let d = Derived()<br class="">
&gt;&nbsp; &nbsp; d.mustBeOverriddenM()<br class="">
&gt;<br class="">
&gt; Then it prints:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; beforeInner<br class="">
&gt;&nbsp; &nbsp; inInner<br class="">
&gt;&nbsp; &nbsp; afterInner<br class="">
&gt;<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
&gt; <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="">
_______________________________________________<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="">
</blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature">Nate Birkholz</div>
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>