[swift-evolution] Proposal: Introduce User-defined "Dynamic Member Lookup" Types

Letanyan Arumugam letanyan.a at gmail.com
Sun Dec 3 20:17:26 CST 2017


I’ve very much been teetering on my preference of having dynamic member lookup sites marked or not and have landed on the side of having it marked. This is for a few reasons:

1. There needs to be some way of conveying that this is not a ‘blessed’ way of writing things.
2. It’s a different paradigm and would benefit a reader by having that documented.
3. It’s weird that code completion, jump to and other code insights stop working for valid members. I’m not worried about having these insights not working though, just the inconsistency. Along with my mental model of my code not working with my tools meaning theres something wrong with my code.

The most minimal way of marking expressions in a way I could think of that would also remove anyones notion of "this code is fully supported static Swift code” would be to use the currently reserved ‘ (Single quote).

Using the code example from another conversation:

let np = Python.import("numpy")
let x = np.array([6, 7, 8])
let y =  np.arange(24).reshape(2, 3, 4)
let a = np.ones(3, dtype: np.int32)
let b = np.linspace(0, pi, 3)
let c = a+b
let d = np.exp(c)

Would become:

let np = Python.import("numpy")
let x = 'np.array([6, 7, 8])'
let y = 'np.arrange(24).reshape(2, 3, 4)'

let a = 'np.ones(3, dtype: np.int32)'
let b = 'np.linespace(0, pi, 3)'
let c = a+b
let d = 'np.exp(c)’

If that is still too heavy a single quote only at the beginning of the expression could be used:

let np = Python.import("numpy")
let x = 'np.array([6, 7, 8])
let y = 'np.arrange(24).reshape(2, 3, 4)

let a = 'np.ones(3, dtype: 'np.int32)
let b = 'np.linespace(0, pi, 3)
let c = a+b
let d = 'np.exp(c)

I’m aware that Python is a dynamic language and would be fine with not having lookups marked if it were just dynamic language wrappers that this proposal affected. A way to get around this could be to use Option 2 of "Reducing Potential Abuse” in the proposal along with having non blessed types require markings or would that be too much of an inconsistency?

FWIW I really hope this proposal goes through, even if it were as is, just for the reason of getting Swift more people. 
Another reason I have to wanting this dynamic feature to be more explicit is that I (like I suspect many others) have been burnt by dynamic features in the past and have run to Swift as a home away from it :)


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

More information about the swift-evolution mailing list