<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></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 Dec 23, 2015, at 7:36 AM, D. Felipe Torres 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 dir="ltr" class="">I've been reading the discussion in "Final by default for classes and methods" and although I don't have a strong position towards what the default behaviour should be, I think a directive to change that behaviour should be added as when nullability was introduced into Obj-C.<div class=""><br class=""></div><div class="">In the current model of Swift, where methods and classes are not final we can ease that by doing something like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class="">ASSUME_FINAL_BEGIN</div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(4,51,255)" class="">class</span> MyClass {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color:rgb(4,51,255)" class="">func</span> aMethod(arg: <span style="color:rgb(52,149,175)" class="">String</span>) {</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color:rgb(4,51,255)" class="">func</span> anotherMethod(number: <span style="color:rgb(52,149,175)" class="">Int</span>) {</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class="">ASSUME_FINAL_END</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><br class=""></div>In this example the whole class is treated as final by the compiler.</div><div class="">On the other hand, in the following example:</div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class="">class<span style="color:rgb(34,34,34)" class=""> </span><span style="color:rgb(34,34,34)" class="">MyClass {</span><br class=""></div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(4,51,255)" class="">ASSUME_FINAL_BEGIN</span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color:rgb(4,51,255)" class="">func</span> aMethod(arg: <span style="color:rgb(52,149,175)" class="">String</span>) {</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="color:rgb(4,51,255)" class="">ASSUME_FINAL_END</span> </div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color:rgb(4,51,255)" class="">func</span> anotherMethod(number: <span style="color:rgb(52,149,175)" class="">Int</span>) {</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">Only aMethod is final, leaving the rest to the default behaviour. (Ok, the example is not different to prepending 'final' but you get the idea).</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">Similarly, should the classes and methods become final by default, a directive to do the opposite should be added (ASSUME_OVERRIDEABLE_(BEGIN|END)?)</div></div></div></div></div></blockquote><br class=""></div><div>We tried to avoid these kinds of contextual blocks because they make reading declarations in isolation much harder. That's one of the reasons we have 'public'/'private' as per-decl modifiers rather than C++/ObjC-style grouping.</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>