And what is with ‘a’ if this situation:
if b == x {
a = 5
}
Nothing :)
Well, it’s not nothing, it has the same value that it had before.
However, as pointed by Leonardo Pessoa, there is a problem with expression:
let a = 5 if b == x
It is equivalent to:
if b == x {
let a = 5
}
but doesn’t communicate clearly that in the next line `a` is already out of
scope and that you cannot write:
let a = 5 if b == x
let c = a // a is not defined here
but you can write:
let a = 1 if b == x
let a = 2 if b == x // other a from other scope
let a = 3 if b == x // another a from another scope
without error concerning immutability.
Austin Zheng has also rightly pointed that this “postfix” syntax looks as if
the if-statement is now an expression, which will further confuse people coming
from languages that use if-expressions.
Also, I find:
{
// … a lot of code
} if b == x
way less readable, simply because I read top to bottom. This syntax makes me
search for the scope delimiter, understand the condition and only after lets me
read the logic.
All the best,
Krzysztof
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution