3 ms·
From Swift documentation: for i in 0..<count { print("Person \(i + 1) is called \(names[i])") } This ..< operator is so much more logical, of course! Not
by dstanko 11y ago
From Swift documentation:
for i in 0..<count {
print("Person \(i + 1) is called \(names[i])")
}
This ..< operator is so much more logical, of course! Not to mention == and ===. Logically, the first one compares twice and the second compares three times (for luck), just in case first two comparisons didn't go through...
- deleted 11y ago[deleted]
- cballard 11y agoI would implement that like: zip(names, 1...names.count).forEach { name, index in print("Person \(index) is called \(name)") } Or, in an ideal world: zip(names, 1...names.count) .map({ name, index in "Person \(index) is called \(name)" }) .forEach(print) Currently, that isn't valid Swift, "print" can't be used like that, though if you define a closure it works: let printIt = { x in print(x) } zip(names, 1...names.count) .map({ name, index in "Person \(index) is called \(name)" }) .forEach(printIt) I think that Swift could use = for equality, since assignments return Void and comparison returns Bool. Maybe it should. But your argument boils down to "if you can't be clear everywhere, don't be clear anywhere". That's not a good goal.
- dstanko 11y agoMy argument ultimately "there are better things to do". At the same time, interpreting ++ as add-add is certainly not an argument. You can say that you don't like infix and postfix operators, but not whether they are readable. If you consider readability, then why !a instead of not(a)? Why || instead of or?
- Shish2k 11y agoSpeaking as somebody who has no idea what X..<Y means, I assume it means "start from X and carry on for as long as you are less-than Y"? Is that correct? I wonder what somebody who had no idea about X++ would guess it meant? Based on my daily conversations, if I didn't know already, I would guess it means "variable X has done a good job and deserves some IRC karma"...
- dstanko 11y agoWhat's an IRC? What's a variable? :) Look, don't get me wrong, I applaud the intent to make the language easy for total beginners. I argue that it's a longer stretch to understand ..< operator than ++. Arguments like people who never programmed before should be able to use it are great, but one should consider those in the context of the entire grammar, not just one operator. In my opinion Swift does not shine here, regardless what Apple says.