[swift-evolution] [Review #2] SE-0161: Smart KeyPaths: Better Key-Value Coding for Swift

Thorsten Seitz tseitz42 at icloud.com
Sun Apr 9 10:11:14 CDT 2017


> https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md <https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md>
> What is your evaluation of the proposal?
+1 in general 

BUT I absolutely dislike having to escape a key path with `\` which is absolutely counterintuitive IMHO.
Like Brent already wrote, the `\` has to encompass the full expression to avoid ambiguities; this is so foreign to how `\` usually works, i.e. only on the following character, that it further makes the syntax counterintuitive and ugly.

I would have preferred one of these

1.
@{Type.property[.property]*}
  // no ambiguities due to braces
  let kp = @{Person.bestFriend?.name}
  luke[keyPath: @{.bestFriend?.name}]

2.
@Type.property[.property]*
  // @ applies to whole expression to make unambiguous (just like Brent suggested for `\`)
  let kp = @Person.bestFriend?.name
  luke[keyPath: @.bestFriend?.name]

3.
Type at property[.property]*
  // @ applies to whole expression to make unambiguous (just like Brent suggested for `\`)
  let kp = Person at bestFriend?.name		
  luke[keyPath: @bestFriend?.name]

4.
Type at property[@property]*
  // no ambiguities due to different separators; might be used for method references as well
  let kp = Person at bestFriend?@name
  luke[keyPath: @bestFriend?@name]

5.
#keyPath(Type.property[.property]*)
  // no ambiguities due to parenthesis
  let kp = #keyPath(Person.bestFriend?.name)
  luke[keyPath: #keyPath(.bestFriend?.name)]


> Is the problem being addressed significant enough to warrant a change to Swift?

Yes, definitely!

> Does this proposal fit well with the feel and direction of Swift?

Yes.

> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?


> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Followed much of the discussion, read the proposal.

-Thorsten

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170409/056f2b52/attachment.html>


More information about the swift-evolution mailing list