<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 13, 2015, at 2:40 AM, David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div 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=""><snip></div></div></blockquote><blockquote type="cite" class=""><div class=""><div 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="">I agree that that would potentially add confusion to the grammar. I've always liked the @ and @@ prefixes of Ruby for accessing instance and class properties, but I agree that symbols like that would feel a bit foreign in Swift.</div><div 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=""><br class=""></div></div></blockquote><div>I believe the interesting bit about Ruby in this case is that it only exposes variables through bound scope. self.foo means ‘call foo on object self’. </div><div><br class=""></div><div>So @foo is *not* shorthand in Ruby, it provides different functionality. This is similar to using this->foo vs self.foo in Objective C.</div><div><br class=""></div><div>-DW</div><br class=""><blockquote type="cite" class=""><div class=""><div 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="">David</div><div 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=""><br class=""></div><div 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="">On 13 Dec 2015, at 10:16, ilya via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" 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=""><div class=""><div dir="ltr" class=""><div class="">> But implicit self is confusing in a lot of code</div><div class=""><br class=""></div><div class="">On the other hand, it allows a logical explanation of how you can take code from global scope and put it into an instance scope:</div><div class=""><br class=""></div><div class="">let greeting = "Hello"</div><div class="">let name = "Michael"</div><div class=""><br class=""></div><div class="">func greet() {</div><div class=""> print("\(greeting), \(name)")</div><div class="">}</div><div class=""><br class=""></div><div class="">seemlessly becomes</div><div class=""><br class=""></div><div class="">class Greeter {</div><div class=""><br class=""></div><div class=""> let greeting = "Hello"</div><div class=""> let name = "Michael"</div><div class=""><br class=""></div><div class=""> func greet() {</div><div class=""> print("\(greeting), \(name)")</div><div class=""> }</div><div class=""><br class=""></div><div class="">}</div><div class=""><br class=""></div><div class="">> can (and does) lead to shadowing bugs,</div><div class=""><br class=""></div><div class="">There are simple strategies that help to minimize the amount of shadowing, e.g. </div><div class=""><br class=""></div><div class="">- only expose the minimum necessary amount of names in any scope </div><div class="">- break functions into small part so that it's easy to see all the local name declarations</div><div class="">- not use any globals, or at least name them in a visually different way (UppercaseCamelStyle)</div><div class="">- name properties and locals in a different way (classProperty, local_var)</div><div class=""><br class=""></div><div class="">Even without a formal code style, if you tend to make property names longer and local names shorter, your risk of shadowing goes down.</div><div class=""><br class=""></div><div class="">> .x and .f() to mark implicit self. I realize that this may conflict with enum usage.</div><div class=""><br class=""></div><div class="">This will lead to a lot of ambiguity:</div><div class=""><br class=""></div><div class="">func f() {</div><div class=""> let x = NSOperation()</div><div class=""> .name = "Name" // is it<span class="Apple-converted-space"> </span><a href="http://x.name/" class="">x.name</a><span class="Apple-converted-space"> </span>or<span class="Apple-converted-space"> </span><a href="http://self.name/" class="">self.name</a>??</div><div class=""> ...</div><div class="">}</div><div class=""><br class=""></div><div class="">> If so, then use another marker. For instance :x or ^x or anything.</div><div class=""><br class=""></div><div class="">This is workable, but still I think this is one of the best points of Swift – the existence of instance scope where names are simply written as-is. This helps implementing patterns like "take a long function and make it into a struct with a bunch of small functions instead".</div><div class=""><br class=""></div><div class="">> is very difficult to reason about in diffs or any other interface that isn't an IDE (especially code review)</div><div class=""><br class=""></div><div class="">This is the point where I entirely agree, good code should be easily read in any context.</div><div class="">Again, may I suggest you take a look into using a style guide to differentiate visually between local and instance scope?</div><div class=""><br class=""></div><div class="">Ilya</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Dec 13, 2015 at 10:15 AM, Rob Napier via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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;"><div dir="ltr" class="">I wanted to reopen this discussion that seems to have trailed off. Requesting the return of self was my very first ask of Swift if I remember correctly (<a href="https://devforums.apple.com/message/1013085" target="_blank" class="">https://devforums.apple.com/message/1013085</a>). Continued work in Swift has both strengthened and modified that ask. Here are several of the examples discussed before:<div class=""><br class=""></div><div class=""><div class=""><a href="https://gist.github.com/schwa/94b11dc0a7a331f46b25" target="_blank" class="">https://gist.github.com/schwa/94b11dc0a7a331f46b25</a></div><div class=""><a href="https://gist.github.com/rnapier/478465d1b15e95b98b42" target="_blank" class="">https://gist.github.com/rnapier/478465d1b15e95b98b42</a></div><div class=""><a href="https://gist.github.com/rnapier/4213dc64206b17df6935" target="_blank" class="">https://gist.github.com/rnapier/4213dc64206b17df6935</a></div><div class=""><a href="https://gist.github.com/dwineman/d6c56ec0c0e2fdb761db" target="_blank" class="">https://gist.github.com/dwineman/d6c56ec0c0e2fdb761db</a></div><div class=""><div class=""><br class=""></div><div class="">I get that it seems tedious to type (and read) "self." and I get that "self." is currently a hint that self might be captured (but doesn't actually mean that, since you can use self. without capturing, and sometimes have to, very often in init, so really it's basically meaningless for that use).</div><div class=""><br class=""></div><div class="">That's why I suggest using .x and .f() to mark implicit self. I realize that this may conflict with enum usage. If so, then use another marker. For instance :x or ^x or anything. But implicit self is confusing in a lot of code, can (and does) lead to shadowing bugs, and is very difficult to reason about in diffs or any other interface that isn't an IDE (especially code review).</div><div class=""><br class=""></div><div class="">Thoughts, David? I agree with your basic proposal; I just want to amend it.</div><div class=""><br class=""></div><div class="">-Rob</div></div></div><div class=""><br class=""></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54PB6QfGHj8FHyiXAU-2BmFfS5mBpWjgxHgjUn6uFtGMhTY5T-2BUIfoxsGQ80Lfgxke88uoXc4nBl6ZM-2FXTHfDd3Se1pAYlk9wJ2gf64FM2FWnfnPm5oEOz-2F-2Bs-2B5ramOTdQYSZyWTSJ-2B81ZnB-2Bgg8-2BSW2uCIQsXIj-2Bb49b6i4dwDm-2F0geafX9DTnN2FJbMtkHrptIM-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span class="Apple-converted-space"> </span><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=""><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=""><br class=""></blockquote></div><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43hXwizS3O2z60WweqomIrdhMWaWWrjucwTpcZ2zT7z3bfnvRKZ-2FAz1CyI8UvVSgMe91KFeU2wP3Bm8wFw-2F8wM2jPI6OAopuloTJQ1xrn3iKFWJDfdDGhSpuyHjaItiXjvIZEwDOefIWzZHJyqZtOxGigl91B0LaYEzxwixMd-2B9SgaCIKb8bViOVdI2loPJ09gsx6qUAIA9z3I1fVqd7CiEA-3D" alt="" width="1" height="1" border="0" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div></blockquote><blockquote type="cite" 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=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43vFcOQoCM-2FU-2BigXPSqPoICIYEMkLM-2FoNlLNCjjksqXnSOWqJcjYLPNMqzCe5lDkL8tNjfoCrM9zGtzk3-2Fc-2Bj6PTO2xHekVcn2Tu1HmsFjbmXqPcuN7C76gyvvrKA7gQK87VASyzmA-2FK145r32-2FeA6p3d4Hz2OSBiCgC0VqH-2BxeUs88lONOkp5bQb3wUamhaCPCNcKwo44wp38rFb0rMIyrY-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=""></body></html>