> On 8 Apr 2017, at 22:18, BJ Homer via swift-evolution
> <[email protected]> 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.
>
> -BJ
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
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution