<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. 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=""> 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=""> }</font></div><div class=""><font face="Consolas" size="2" class=""><br class=""></font></div><div class=""><font face="Consolas" size="2" class=""> 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=""> }</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. </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> part to be after the call to <font face="Consolas" size="2" class=""><b class="">someMethod()</b></font>. </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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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=""> func viewDidLoad() {<br class=""> // does something<br class=""> }<br class="">}<br class=""><br class="">class Button: View {<br class=""> override func viewDidLoad() {<br class=""> super.viewDidLoad() // <— this might be forgotten<br class=""> // do something other<br class=""> }<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=""> extend func viewDidLoad() {<br class=""> super.viewDidLoad()<br class=""> // do something<br class=""> }<br class=""><br class=""> extend func viewDidAppear() {<br class=""> // do something<br class=""> } // <— the compiler should throw an error here.<br class="">}<br class=""><br class="">// Example for replacing a function<br class="">class Geometry {<br class=""> func volume() -> Double {<br class=""> return 0;<br class=""> }<br class="">}<br class=""><br class="">class Cube: Geometry {<br class=""> var length: Double = 0.0<br class=""> replace func volume() -> Double {<br class=""> let v = length * length * length<br class=""> return v<br class=""> }<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>