<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">Hi Mustafa,</p>
<p style="margin:0px 0px 1.2em!important">This is an interesting idea. The wording needs to be clear that it is not adding/injecting any code into the super-class. I would call it something like a cascading or chained method - there may be a better name and probably already is, because <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">deinit</code> already behaves in a similar way - the compiler enforces that you don’t call it directly and it cascades the calls up the super-class chain skipping ones where <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">deinit</code> is not implemented.</p>
<p style="margin:0px 0px 1.2em!important">I think this should be something declared in the super-class though, not something that a sub-class would use for the convenience of omitting the <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">super</code> call. That is, the super-class demands of the compiler that its implementation is always called when this method is called on any sub-class (and this enforcement is inherited so all implementations in each sub-class are guaranteed to be called).</p>
<p style="margin:0px 0px 1.2em!important">A class could declare a method to be <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">chained</code> (or whatever) and the compiler would ensure that overrides definitely call the <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">super</code> method, or automatically inject it if they don’t. This would give sub-classes the flexibility to call it anywhere they like (before or after or in the middle of their implementation) and they could also modify the parameters passed to it. There could also be head/tail variations that enforce <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">super</code> is called at the beginning or end of sub-class implementations, rather than anywhere.</p>
<p style="margin:0px 0px 1.2em!important">This is also similar to how the compiler enforces the <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">init</code> calls are made up the class hierarchy, but with <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">init</code> each sub-class might have different parameters for their initialisers. However with a method, if you introduce different/additional parameters it is now a new method, and no longer an override. Would it be desirable to enforce a chain in this case - when a sub-class wants to change the signature part way down the chain such that all its sub-classes cannot override the original method but must use a different one instead? This seems related but probably needs a lot more thought and a diverse set of examples to guide the design.</p>
<div title="MDH:PGRpdj48ZGl2PkhpIE11c3RhZmEsPGJyPjxicj48L2Rpdj5UaGlzIGlzIGFuIGludGVyZXN0aW5n
IGlkZWEuIFRoZSB3b3JkaW5nIG5lZWRzIHRvIGJlIGNsZWFyIHRoYXQgaXQgaXMgbm90IGFkZGlu
Zy9pbmplY3RpbmcgYW55IGNvZGUgaW50byB0aGUgc3VwZXItY2xhc3MuIEkgd291bGQgY2FsbCBp
dCBzb21ldGhpbmcgbGlrZSBhIGNhc2NhZGluZyBvciBjaGFpbmVkIG1ldGhvZCAtIHRoZXJlIG1h
eSBiZSBhIGJldHRlciBuYW1lIGFuZCBwcm9iYWJseSBhbHJlYWR5IGlzLCBiZWNhdXNlIGBkZWlu
aXRgIGFscmVhZHkgYmVoYXZlcyBpbiBhIHNpbWlsYXIgd2F5IC0gdGhlIGNvbX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3ViLWNsYXNzZXMgY2Fubm90IG92ZXJyaWRlIHRoZSBvcmlnaW5hbCBtZXRob2QgYnV0IG11c3Qg
dXNlIGEgZGlmZmVyZW50IG9uZSBpbnN0ZWFkPyBUaGlzIHNlZW1zIHJlbGF0ZWQgYnV0IHByb2Jh
Ymx5IG5lZWRzIGEgbG90IG1vcmUgdGhvdWdodCBhbmQgYSBkaXZlcnNlIHNldCBvZiBleGFtcGxl
cyB0byBndWlkZSB0aGUgZGVzaWduLjxicj48ZGl2Pjxicj48L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 16 Nov 2016 at 22:30 Mustafa Sabur via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">Hallo,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I have a very simple suggestion. And I’m not very sure then it haven’t been discussed already, so I’m sorry if that is the case.</div><div class="gmail_msg">I would like to see the ability to just add code to base methods instead of overriding it and calling supers method. So basically an extension for methods.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Example:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Now:</div><div class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>override func viewDidLoad() {</div><div class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">                </span>super.viewDidLoad()</div><div class="gmail_msg"><i class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">                </span>// Your code</i></div><div class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Suggestion:</div><div class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>addinto func viewDidLoad() {</div><div class="gmail_msg"><i class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">                </span>// Your code</i></div><div class="gmail_msg"><span class="m_8085987590264440970Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">My reasons:</div><div class="gmail_msg">1. Its very verbose about your intentions, which fits into Swift style. The thing you actually want is not overriding but appending. </div><div class="gmail_msg">2. You cannot make the mistake of forgetting to call the supers method.</div><div class="gmail_msg">3. It open ways to introducing ‘semi-final’ methods, which cannot be override but you still can append to it. </div><div class="gmail_msg">    This to make sure your API implementation will always be executed . I’m thinking about a keyword like extendable to specify that you can only add to it.</div><div class="gmail_msg">4. Less code.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I can’t think of any cons... Thought I can imagine that the benefits are quite small and maybe not worth the effort.</div><div class="gmail_msg">I would like to read some thoughts about this. Thank you!</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Kind regards,</div><div class="gmail_msg">Mustafa Sabur</div><div class="gmail_msg"><div class="gmail_msg"><br class="m_8085987590264440970Apple-interchange-newline gmail_msg" style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_8085987590264440970Apple-interchange-newline gmail_msg">
</div>
<br class="gmail_msg"></div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>