[swift-evolution] [Review #2] SE-0161: Smart KeyPaths: Better Key-Value Coding for Swift
rparada at mac.com
Sat Apr 8 20:11:47 CDT 2017
At one point I was leaning towards a trailing backslash. Now I prefer parenthesis.
If parentheses are used should the escape character be outside the parenthesis or inside? For example:
let x = (\Person.mother.age).valueType
let y = (\Person.mother.age.valueType)
let x = \(Person.mother.age).valueType
let y = \(Person.mother.age.valueType)
It is a subtle difference.
> On Apr 8, 2017, at 5:47 PM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>> On 8 Apr 2017, at 22:18, BJ Homer via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> I love the idea of a leading and trailing backslash. It makes it much easier to read, and handles the "but what if I want to access a property of a KeyPath?" case really well.
>> For example, these two are clearly distinct:
>> let x = \Person.mother.age\.valueType
>> let y = \Person.mother.age.valueType\
>> I'm not sure why an 'age' object would have a 'valueType' property, but this variant makes it easy to handle. Even in cases where no disambiguation is required, having the trailing backslash makes it much easier to read as I'm scanning through code.
> I think I'd prefer brackets for that case; in your first example that reads to me like an escape of the period character, rather than "this is the end of the key path". Brackets would make this consistent with escaping within strings, like so:
> let x = \(Person.mother.age).valueType
> let y = \(Person.mother.age.valueType)
> Which makes sense to me if you consider the backslash in this case being an escape from normal type/variable access. Put another way, normally when you type Person. you're telling Swift "access this type and look for static methods/properties etc.", whereas when you "escape" it you're telling Swift to not to do that, resulting in a key-path instead.
> Maybe it's a stretch, it that makes sense logically to me, plus I think the use of brackets just looks cleaner than another backslash.
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution