[swift-evolution] thoughts on 'inout'
Brent Royal-Gordon
brent at architechies.com
Fri Feb 12 18:00:48 CST 2016
> I'm not sure what you mean by heavier and lighter.
> I've never looked at the statement
> var a = 7
> and wished I could use a lighter : instead of the =
> (did I understand you correctly on this point?)
What I mean is that `:` is visually "smaller" than `=`; when you're reading code, it shows up less prominently. That means colon is better suited for the more common and less dangerous role of marking in-only parameters.
> inout parameters are not rare in my code. I'd say they are about as common as only in parameters,
> and even then, the vast majority of my functions have them.
Then I think you're writing in a fairly unusual style, which may explain the disconnect. Most Swift code I've seen uses inout parameters very rarely—perhaps one function in fifty will have an inout parameter.
Are you sure that using inout instead of passing, modifying, and returning the arrays is gaining you anything? Swift arrays are backed by copy-on-write storage, so in theory with optimizations enabled you might not not need to copy the data in a pass-and-assign-back pattern. If this were the case, it would probably only show up in optimized builds, not debug builds.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list