<div dir="ltr"><div><div><b>Proposal:</b></div><div><br></div><div>I propose adding setter methods to vars, which could look something like this: `ApiClient().fetchUsers().then(#set(users))`</div><div><br></div><div>Initially I thought it should work like this: `ApiClient().fetchUsers().then(users.set)`</div><div>but to accomplish a line of code that flows grammatically, I believe putting "set" where it would naturally fall if the code was being read as a sentence is more Swifty.</div></div><div><br></div><div><b>Rationale:</b></div><div><br></div><div>The following code makes me smile:</div><div><br></div><div>ApiClient().fetchUsers().then(displayUsers)</div><div><br></div><div>It exemplifies the beauty of Swift. First-class functions make this line of code read very well. Consider some alternatives:</div><div><br></div><div>1. ApiClient().fetchUsers().then { displayUsers($0) }<br></div><div>2. ApiClient().fetchUsers().then { users in displayUsers(users) }<br></div><div>3. ApiClient().fetchUsers().then { (users: [User]) in displayUsers(users) }</div><div><br></div><div>Using the lessons learned from Swift API Design Guidelines (WWDC 2016 Session 403) having an emphasis on clarity, my analysis of the alternatives is:</div><div><br></div><div>1. $0 adds no additional information as to the type or explanation of what the argument is, thus adding nothing to the line of code for clarity, and therefore should be omitted</div><div>2. adding "users" also adds nothing to the clarity of the code. The function, properly, contains the information necessary to reason about the argument it takes and what it does, and therefore adding "users" is redundant</div><div>3. Not only is "users" redundant, but also is the explicit type label. The `displayUsers` method will only accept one type of argument, so we're duplicating information that the compiler (and autocomplete) already gives us</div><div><br></div><div>With this I conclude that `ApiClient().fetchUsers().then(displayUsers)` is the Swiftiest option.</div><div>I want to extend this same logic to when I find myself writing code like this:</div><div><br></div><div>ApiClient().fetchUsers().then { users in<br></div><div> self.users = users</div><div>}</div><div><br></div><div>or alternatively, because "users" is likely redundant information again,</div><div><br></div><div>ApiClient().fetchUsers().then { self.users = $0 }<br></div><div><br></div><div>Personally I steer clear of `$0` as much as possible, because I very rarely feel that it provides the information necessary for code clarity. But beyond that, this code no longer reads as nicely as the code we had before. </div><div><br></div><div>Whereas `ApiClient().fetchUsers().then(displayUsers)` flows nicely as a sentence and reads grammatically, `ApiClient().fetchUsers().then { self.users = $0 }` no longer does.</div><div><br></div><div>I think this feature could have a simple implementation where the compiler replaces `#set(X)` with `{ X = $0 }`, and I believe it would go a long way with respect to code clarity, especially when X is something longer like `self.view.bounds.origin.x`<br></div><div><br></div><div><br></div><div>Looking forward to hearing thoughts from the community,</div><div><div data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><div dir="ltr" style="font-size:12.8px"><div dir="ltr" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px"><font face="arial,helvetica,sans-serif" color="#000000" style="font-size:12.8px"><b>Austin Feight<br></b></font></div><div dir="ltr" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><div></div></div></div></div></div></div></div></div></div></div></div>
</div>