Edit: I'm only half-joking. Removing postincrement and postdecrement from C++, as some people are suggesting, would be like removing the oil filler cap from a chain saw. The tool would still be dangerous to use, but now it's annoying to use as well.
If readability matters then the rationale that x += 1 is more readable than x++ is very reasonable.
maybeNull?.getContent()?.toString()
This would improve my coding sooo much.
Currently I use Optional.fromNullable(maybeNull).orElse(new DummyObjectThatReturnsNullOnAllMethodCalls).getContent(), and then repeat the process.
I've always found the idea that the operator complicates things ridiculous
Given that there are interview questions on the behavior of post/pre increment operators shows that there is some subtlety to it which creates ambiguity and complexity. So given that they want the language to be accessible, it makes sense to reduce ambiguity.Being an interview question doesn't really mean anything other than it being an interview question.
It looks like they may be trying to make it easier for current tweens that would have otherwise learned PHP.
Don't see the value in this. These operators are terse, well known, and are implemented in a wide array of languages.
"plus plus" doesn't mean anything. It might even be confusing that it doesn't add 2.
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...
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.
If you consider readability, then why !a instead of not(a)? Why || instead of or?
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"...
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.
This half-reeks of something that a professional/advanced user thinks trips up beginners without actually tripping up beginners. Or they have an anecdotal sample size of n < 10 and decided since it confused 1 person that 10% of people get confused.