[swift-evolution] [Proposal] Use inout at function call sites
Dmitri Gribenko
gribozavr at gmail.com
Fri Jan 29 16:49:39 CST 2016
On Fri, Jan 29, 2016 at 2:44 PM, Trent Nadeau via swift-evolution
<swift-evolution at swift.org> wrote:
> The `&` prefix operator is a holdover from C where it is usually read as
> "address of" and creates a pointer. While very useful in C due to its
> pervasive use of pointers, its meaning is not the same
Since there is an implicit conversion from &x expression to
UnsafePointer (for C interop), I have seen so many times people write
buggy code with the & operator, assuming that it is returning a stable
inner pointer to the data structure, like in C. I don't have a
preference for the replacement, but I strongly believe that & is the
wrong way to spell this operation, because of the strong (and wrong!)
connection with C syntax that people tend to make. 'inout' keyword at
the call site sounds like a fine replacement to me.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the swift-evolution
mailing list