[swift-evolution] [Proposal] Use inout at function call sites
jordan_rose at apple.com
Fri Jan 29 21:57:36 CST 2016
> On Jan 29, 2016, at 19:45 , Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> 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.
This is already true. Are you thinking of something else?
More information about the swift-evolution