[swift-evolution] Hidden initiallizations ...

Biala bialata at yahoo.com
Tue Mar 29 00:42:51 CDT 2016

 I strongly disagree with you. You can not "accidentally" do any thing as the name of the variable used will be written. Now it is written "i" and is not cleat what i is...
Adding "let" may help but only in case that it is not allowed to use the name "i" in the same method. Having more that one variable with the same name in one method is stupid and the language should prevent that at least. 


    On Tuesday, March 29, 2016 4:16 AM, Brent Royal-Gordon <brent at architechies.com> wrote:

 > What is the value of i ??

0, because `for i` implicitly declares a new variable `i`. You could perhaps argue that you should have to explicitly say `for let i`, but that seems pointless because the `let` would always be necessary. (Well, unless you did a `for case` or `for _`, but those are rare constructs.)

> My suggestion is to use the variable i in the loop instead of making hidden init of another "i" for the loop. 

That seems like an extremely bad idea. What if the loop variable is a property or global and you accidentally end up using it implicitly? That's *way* worse than shadowing the outer variable.

Brent Royal-Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160329/3f20f28e/attachment-0001.html>

More information about the swift-evolution mailing list