<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>-1 also for reasons already listed.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">I would even like ways to have more implicit self, like method cascading, closure binding, implicit self in a closure if self is explicitly captured, etc… </div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">-- <br>Pierre</div><div><br>Le 16 déc. 2015 à 14:55, Taras Zakharko via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> a écrit :<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">I think the most important advantage of explicit self is that it vastly simplifies the scoping rules of the language as it moves the instance scope into a clearly recognisable construction. As far as I am concerned, self should be mandatory. However, I can also understand that sometimes it might get a bit repetitive (especially when initialising state). This thread is getting a bit large, so sorry if I missed, but did anyone already suggest to introduce a scope operator, which would bind a particular instance to the top of the variable scope. Such operator could be integrated into the existing do, e.g.</div><div class=""><br class=""></div><div class="">do with self { // or with self do</div><div class=""> x = 1</div><div class=""> y = 2</div><div class="">}</div><div class=""><br class=""></div><div class="">similarly</div><div class=""><br class=""></div><div class="">do with obj {</div><div class=""> x = 1</div><div class=""> y= 2</div><div class="">}</div><div class=""><br class=""></div><div class="">This has the benefit of keeping the scoping rules simple, preventing clashes between the instance scope and the block/function/global scope, while retaining the possibility to use the ‘more readable’ form if needed. Furthermore, it can be also seen as a neat logical ‘grouping' construct that aids the programmer in understanding the code better. </div><div class=""><br class=""></div><div class="">Again, I apologise if this suggestion was already made, I might have overlooked it. </div><div class=""><br class=""></div><div>Best, </div><div><br class=""></div><div> Taras<br class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">-DW</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"> <br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 3:46 PM, Honza Dvorsky 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="">Hi all,<br class=""><br class="">I've been following the thread from the beginning and some great arguments have been layed out. As far as I understand, this proposal would lead to fewer correctness bugs (referring to a different variable due to implicit self, has happened to me twice in the last couple of months, was very hard to track down).<span class="Apple-converted-space"> </span><br class=""><br class="">The disadvantages of this are only verbosity. But, from the design principles of Swift (as I understand them), correctness is preferred over making the language concise, especially when those two are in conflict, just like here.<span class="Apple-converted-space"> </span><br class=""><br class="">I support the proposal, because it would lead to fewer bugs at only the cost of extra few characters. Again, I've been bitten by implicit self a couple times before and those bugs are hard to track down. And the readability of the code in code reviews, to me, is another huge advantage, possibly leading to more correctness bugs caught early.<span class="Apple-converted-space"> </span><br class=""><br class="">I understand and appreciate the disadvantages, but again, I believe we should prefer correctness over conciseness, as explicitly stated by the Swift design principles.<span class="Apple-converted-space"> </span><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Dec 15, 2015 at 11:28 PM Slava Pestov via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Hi all,<br class=""><br class="">I don't see anyone lay out how this proposal can interact with nested types and such. There's a fair amount of complexity in Swift with what you can do by nesting things inside of each other, so the simple conceptual model of "locals are unqualified, instance variables have a self. prefix" doesn't seem to generalize.<br class=""><br class="">Will I need to qualify associated types with the protocol or type name to refer to them? What about generic type parameters, they're sort of like "instance variables" too.<br class=""><br class="">What about class methods that want to call each other? Do they need the explicit 'self', or an explicit class name prefix? The latter changes semantics if the class method is overridden in a subclass.<br class=""><br class="">If we ever add the ability for an inner type to capture stored properties from the outer type, how do you reference properties of the outer type? I guess the problem has to be solved anyway to refer to an outer "self" explicitly, but qualifying everything with OuterType.self.foo kind of defeats the purpose of inner types altogether.<br class=""><br class="">I'm not sure I buy the readability arguments in favor of this approach. It seems the languages where explicit 'self' was adopted did it mostly by accident, or because of implementation concerns. In Python for instance, there's no way for assignment to modify a binding in an outer scope, so 'foo = bar' always sets a local named 'foo', IIRC. So explicit self is needed there. Greg Parker explains earlier in this thread by explicit self was chosen for Objective-C, and it wasn't readability.<br class=""><br class="">Slava<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" 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><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43vFcOQoCM-2FU-2BigXPSqPoICLSYWobY86j21ljTgKcXT-2F00-2F3YI1smlxeyMjWVgsvmdfRNKJBMcvdsXG-2B3kQEmZBYx8SUZghc1U0hbp2ayUiV5sHfajb6ETgGUdJl8Z8s1e5Sy0gqR48zCNNjEJjM8l1HfCaMigtH-2Bri53ALbGX10HTJ4saHWV4qGaaTVCSnjVeqdQ1Rwdu4uBxWUQfyoO-2FCY-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"><span class="Apple-converted-space"> </span>_______________________________________________<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" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=x4DBtcYZPuS8wt8fMTVYDXzwU9szxEmdHE1DwQfVzUekVmJEfOxIxEk-2BzdsjoT0d939m-2BhQaDNy5xOEk8h3VtoU0BXoxnSPAsmW5blVYgnjVOj-2BCnKudHYDP6Q45okRD-2BgEQs48P6dxikzv48GiC44xBX4jBr1haxaPHlDoWBNBL0Otv6IBs7rusT4LA5GZegAiVTqa3SahNKhKzcLvX-2BRIo-2FN3d66cd2o9h6-2B-2BOWco-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ST9LHNQ2kYRKURQJ7G-2FmGCudH8brFLVBGfh-2Becw1t9ghhv-2B1sDV2M6IuP57udNJFmFy9eUp2zBkevqpeIYon9tow8kjrvDWHmi0YcFaf-2BVttW88-2FKVLcv7bseqkIgQjncf9wMZxfaY8-2B3qbFA3-2FA9OGgcvV58z1nbCt4iW2w7JqQ2Gb-2BmZFCJKF23-2FijRIebgqgqpVoGk0Ykl8d8Ch0PhmSYLyD3Z7oGXFxdro2p9uM-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>