My biggest surprise with Swift was the removal of the pre and post increment and decrement (++ and --) in Swift 3. These are well defined and commonly used operators — heck, the name of one of the most popular languages is a word-play on the post-increment operator. In fact, you'd be hard-pressed to find another modern language out there that does not have them.
My real issue is that they are part of the coding part of my brain — when I want to increment, I automatically type "++". Sure, Xc
Well, my question was not "why were they removed?", but "what can I do to get them back?". And they were removed -- they were there!
I have seen the link (back when it was just a proposal), and I cannot find a compelling removal reason in the list of disadvantages. Let's cover each in turn:
1. new users. Add one or subtract one is difficult? I think not. Plus, removing a great feature because it may be difficult for some users to learn is weak — might as well ban regular expressions all together
Fair enough, but those arguments were considered at the time and the balanced choice was made to remove.
Sure, I'd love to have the ? : operator.
Swift does have the conditional operator. Some people make the mistake of trying it and concluding it doesn't work. But they've neglected to seprate the ? from the condition with a space, and thus made the compiler think they were trying to unwrap an optional.
It also has the ?? : nil coalesing operator. Again spaces are required.
I agree it was a mistake. This and the removal of the C style for loop sucked away a huge quantity of energy in the early days of swift evolution.
The good news with ++ and -- is that it is trivial to put them back in.
prefix func ++(n: inout Int) -> Int { n = n + 1 ; return n }
postfix func ++(n: inout Int) -> Int {defer { n = n + 1 } ; return n }
Somebody should do a survey on Github Swift projects to see how many of them define those operators. If it is a lot, we can assume Swift.org made a mistake.
There's two common uses I've seen for ++ and --. One is to serve as a complete statement or equivalent (for (int i = 0; i 10; ++i)), and one is inside an expression. For a complete statement, it's not much of a problem to use += 1 or -= 1. Inside an expression, it makes the expression have side effects, and I don't think that's a good idea in general, particularly when it's not just in one thread.
"Our reruns are better than theirs."
-- Nick at Nite
Increment and decrement (Score:1)
My biggest surprise with Swift was the removal of the pre and post increment and decrement (++ and --) in Swift 3. These are well defined and commonly used operators — heck, the name of one of the most popular languages is a word-play on the post-increment operator. In fact, you'd be hard-pressed to find another modern language out there that does not have them.
My real issue is that they are part of the coding part of my brain — when I want to increment, I automatically type "++". Sure, Xc
Re:Increment and decrement (Score:2)
He already gave a full list of reasons why at the time the change was proposed.
https://github.com/apple/swift... [github.com]
Re: (Score:1)
Well, my question was not "why were they removed?", but "what can I do to get them back?". And they were removed -- they were there!
I have seen the link (back when it was just a proposal), and I cannot find a compelling removal reason in the list of disadvantages. Let's cover each in turn:
Re: (Score:2)
Fair enough, but those arguments were considered at the time and the balanced choice was made to remove.
Sure, I'd love to have the ? : operator.
Swift does have the conditional operator. Some people make the mistake of trying it and concluding it doesn't work. But they've neglected to seprate the ? from the condition with a space, and thus made the compiler think they were trying to unwrap an optional.
It also has the ?? : nil coalesing operator. Again spaces are required.
Re: (Score:2)
I agree it was a mistake. This and the removal of the C style for loop sucked away a huge quantity of energy in the early days of swift evolution.
The good news with ++ and -- is that it is trivial to put them back in.
prefix func ++(n: inout Int) -> Int { n = n + 1 ; return n }
postfix func ++(n: inout Int) -> Int {defer { n = n + 1 } ; return n }
Somebody should do a survey on Github Swift projects to see how many of them define those operators. If it is a lot, we can assume Swift.org made a mistake.
Re: (Score:2)
There's two common uses I've seen for ++ and --. One is to serve as a complete statement or equivalent (for (int i = 0; i 10; ++i)), and one is inside an expression. For a complete statement, it's not much of a problem to use += 1 or -= 1. Inside an expression, it makes the expression have side effects, and I don't think that's a good idea in general, particularly when it's not just in one thread.