[swift-evolution] [Proposal] Use inout at function call sites
Brent Royal-Gordon
brent at architechies.com
Fri Jan 29 21:45:47 CST 2016
> add1(&n) // n is now 6
> add1(inout n) // symmetric and now obvious that n can change
I'm not a really big fan of this change; despite being longer, `inout n` is less visible to me than `&n`. But this is a relatively weak preference—I could certainly live with it.
More important than changing the symbol might be restricting its use. I don't see any particularly good reason to permit you to say `let x = &y`. Far better to use `withUnsafePointer()` to control the scope of the pointer, or at least say something like `let x = unsafeInoutPointer(&y)` to acknowledge that you're circumventing memory safety and possibly taking a pointer to a temporary. Basically, I think `&` or `inout` or however we spell it should only be allowed as a parameter, not just anywhere in any expression.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list