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

David Hart david at hartbit.com
Mon Apr 3 05:45:54 CDT 2017

> What is your evaluation of the proposal?
I am very excited about the usefulness of this proposal right now and about its potential in the future. This is big step towards enabling a lot of “dynamic” features.

But, like Brent, I continue to think that the syntax is much too heavy: I was a big fan of the original version of the proposal. If we take the code Brent wrote in this thread:

let isPuppyQualifier = #keyPath(Pet, .type) == .dog && #keyPath(Pet, .age) < 12
let familyQualifier = #keyPath(Family, .pets).contains(where: isPuppyQualifier)
let familiesWithPuppies = Family.fetch(editingContext, familyQualifier)

We can see that it’s much less readable than if written with the original proposal:

let isPuppyQualifier = Pet.type == .dog && Pet.age < 12
let familyQualifier = Family.pets.contains(where: isPuppyQualifier)
let familiesWithPuppies = Family.fetch(editingContext, familyQualifier)

Or with any other similar alternative:

let isPuppyQualifier = Pet::type == .dog && Pet::age < 12
let familyQualifier = Family::pets.contains(where: isPuppyQualifier)
let familiesWithPuppies = Family.fetch(editingContext, familyQualifier)

I would strongly suggest that the core team reconsider the syntax in the latest version of the proposal and revert to the original form or something similar. Even if the original syntax is chosen, the ambiguity issues that existed in that version is only a small price to pay next to the improvement in readability this popular feature will gain.

> Is the problem being addressed significant enough to warrant a change to Swift?
Yes, very much.

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

> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
I have used key-paths in Objective-C, but this feature is more similar to lenses than to Objective-C’s key-paths. I have not used lenses in another language.

> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
An in depth-study.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170403/0eb70784/attachment.html>

More information about the swift-evolution mailing list