<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="">Hi Florian,<div class=""><br class=""></div><div class="">I have always taken care of this problem in other languages without recurring to specialized language features. &nbsp;For example:</div><div class=""><br class=""></div><div class=""><font face="Consolas" size="2" class="">class Foo {</font></div><div class=""><font face="Consolas" size="2" class="">&nbsp; &nbsp; func <font color="#942192" class="">_someMethod</font>() {</font></div><div class=""><font face="Consolas" size="2" color="#438139" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// Do something important</font></div><div class=""><font face="Consolas" size="2" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>…</font></div><div class=""><font face="Consolas" size="2" class=""><br class=""></font></div><div class=""><font color="#438139" face="Consolas" size="2" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>// Now give subclassers a chance to do something</font></div><div class=""><font face="Consolas" size="2" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><b class="">someMethod()</b></font></div><div class=""><font face="Consolas" size="2" class="">&nbsp; &nbsp; }</font></div><div class=""><font face="Consolas" size="2" class=""><br class=""></font></div><div class=""><font face="Consolas" size="2" class="">&nbsp; &nbsp; func <b class="">someMethod()</b> {</font></div><div class=""><font color="#438139" face="Consolas" size="2" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>// Default does nothing</font></div><div class=""><font face="Consolas" size="2" class="">&nbsp; &nbsp; }</font></div><div class=""><font face="Consolas" size="2" class="">}</font></div><div class=""><br class=""></div><div class="">This way you are in control when someone else overrides someMethod since <font color="#942192" face="Consolas" size="2" class="">_someMethod</font>() does the important stuff first and then calls someMethod() to allow those extending the class to do something.&nbsp;</div><div class=""><br class=""></div><div class="">Also, I can modify <font color="#942192" face="Consolas" size="2" class="">_someMethod() </font>and move the <font color="#438139" face="Consolas" size="2" class="">“Do something important”</font>&nbsp;part to be after the call to <font face="Consolas" size="2" class=""><b class="">someMethod()</b></font>. &nbsp;</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 15, 2016, at 3:57 PM, Florian Liefers 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 class="">Hi!<br class=""><br class="">I would like to suggest to replace the override keyword for functions by something like extend and replace or to add an annotation like @SuppressSuperCall (don’t know a good name for it).<br class="">The reason for this is, that it might happen, that one forgets to call the super’s implementation in an overridden function or if one reads the code it might not be obvious why the super’s implementation is not called:<br class=""><br class="">class View {<br class=""> &nbsp;&nbsp;func viewDidLoad() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// does something<br class=""> &nbsp;&nbsp;}<br class="">}<br class=""><br class="">class Button: View {<br class=""> &nbsp;override func viewDidLoad() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.viewDidLoad() &nbsp;&nbsp;// &lt;— this might be forgotten<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// do something other<br class=""> &nbsp;&nbsp;}<br class="">}<br class=""><br class="">The compiler will accept if one overrides a superclass’s function but does not call the superclass’s implementation which is often ok. The developer should clearly state that he doesn’t want to call the superclass’s implementation, otherwise the compiler should throw an error.<br class=""><br class="">// Example for extending a function<br class="">class Button: View {<br class=""> &nbsp;extend func viewDidLoad() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.viewDidLoad()<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// do something<br class=""> &nbsp;&nbsp;}<br class=""><br class=""> &nbsp;extend func viewDidAppear() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// do something<br class=""> &nbsp;&nbsp;} // &lt;— the compiler should throw an error here.<br class="">}<br class=""><br class="">// Example for replacing a function<br class="">class Geometry {<br class=""> &nbsp;&nbsp;func volume() -&gt; Double {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br class=""> &nbsp;&nbsp;}<br class="">}<br class=""><br class="">class Cube: Geometry {<br class=""> &nbsp;&nbsp;var length: Double = 0.0<br class=""> &nbsp;&nbsp;replace func volume() -&gt; Double {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let v = length * length * length<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return v<br class=""> &nbsp;&nbsp;}<br class="">}<br class=""><br class="">Cheers,<br class="">Florian<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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></div></body></html>