I had no idea there was even a debate about this let alone people passionate about each side. This is bike shedding right?
Remove the ++ and –- operators
231–240 of 249 posts
Re: Remove the ++ and –- operators
#232Earlier quoted context omitted.
From Swift documentation: for i in 0.. 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...
Speaking as somebody who has no idea what X.. 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 ..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.
Re: Remove the ++ and –- operators
#233Earlier quoted context omitted.
I don't get the argument... you have to learn what "+" does, so why not remove that and just have "-" since you can subtract negative numbers to add. The line of reasoning that it is more to learn is ridiculous. The concept of incrementing or decrementing a value is trivial. If "++" seriously trips you up as you learn to program, perhaps programming isn't for you... "+=" is no better. If you're going to campaign agai…
x = x + 1 isn't so fun when you're writing long_variable_name = long_variable_name + 1 That's the problem being solved in a modern language. The ++ and -- operators don't add much. They're the perfect a combination of rare, unnecessary, and often ambiguous. Not to mention that their semantics are often different in subtle ways between languages.
Autocompletion is a wonderful tool that every developer should use, if only to reduce the possibility of `long_variable_name = long_varable_name + 1` in their code.
Re: Remove the ++ and –- operators
#234Earlier quoted context omitted.
The assignment aspect of __iadd__ is done like any other assignment in python. The one to one equivalent of eliteraspberrie's would be: class Vector2D: def __iadd__(self, other) return self + other No "self mutation" as you suggest. a += b is equivalent to a = a.__iadd__(b)
> No "self mutation" as you suggest. Your example would be the implementation for immutable Vector2Ds, and is implemented for you if you just wrote __add__. (I presume object.__iadd__ falls back to self.__add__.) The only time you should actually override __iadd__ is for mutable objects, in which case it should look more like class Vector2D: def __iadd__(self, other) for i, x in enumerate(other): self[i] += x return…
What would the rationale be for such a rule?
the docs don't mention anything like that https://docs.python.org/2/library/operator.html and I've never heard it before. In Python, neither integers nor strings are mutable and both support the "x += y" syntax.
The __iadd__ method works the same for both mutable and immutable objects AFAIK
Re: Remove the ++ and –- operators
#235Earlier quoted context omitted.
I think I'd argue with the "not much shorter" because it's less typing to perform a `++` versus `+=1`; I hold shift, I type the = key, obtaining the +, then I have to pause typing long enough to release the shift key, type the = key again, and now my other hand has to get involved and type a 1. And that's without the spaces.
Typing is not the bottleneck.
I had a very similar conversation with a colleague about UX. This one operation might not happen often, but when it does, it should be intuitive and fast. The technology is here to serve the humans.
Re: Remove the ++ and –- operators
#236Earlier quoted context omitted.
I think I'd argue with the "not much shorter" because it's less typing to perform a `++` versus `+=1`; I hold shift, I type the = key, obtaining the +, then I have to pause typing long enough to release the shift key, type the = key again, and now my other hand has to get involved and type a 1. And that's without the spaces.
If typing is the bottleneck in your development you're not solving difficult problems and could probably make more money solving difficult problems at a different job.
Re: Remove the ++ and –- operators
#237Earlier quoted context omitted.
Almost every C and C++ book I've seen has an, imho, needless chapter on why "y = x++" and "y = ++x" are not the same thing. This does not reduce clutter.
Public service announcement: If you can't keep this stuff straight, C++ may not be for you. 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.
Re: Remove the ++ and –- operators
#238"When the return value is needed, the Swift += operator cannot be used in-line, since (unlike C) it returns Void." Why was this decision made?
So you can't do this: a += b -= c; Don't ask me in which order it executes, I would need to read the C standard again and wrap my head around how this case is described therein. I'm also not sure wether this is defined or undefined behaviour: a += b -= c *= a;
thx for the reply @legulere, I can now see the void, why would the language allow syntax that smells so bad? Can you do this in "c"?
Re: Remove the ++ and –- operators
#239Earlier quoted context omitted.
Typing is not the bottleneck.
Yes, typing is indeed the bottleneck. Perhaps it doesn't add up to much time overall, but until we get brain-computer interfaces and the ability to will code or instructions into existence, I want every barrier to moving the solution from my head into the computer as small as possible. I had a very similar conversation with a colleague about UX. This one operation might not happen often, but when it does, it should b…
That is, if you're optimizing typing, you're optimizing the wrong thing, and if you want to improve your ability to write software, you should instead be getting better at these other things. The typing part is good enough.
Edit: Or if typing really is the bottleneck, you're a much better programmer than me.
Re: Remove the ++ and –- operators
#240Earlier quoted context omitted.
>Why does '+' (and friends) get this special form, but not my functions? Your functions can get that (and other) special form. You need to use a language where you can define your own operators. Have you looked at C++, C#, Haskell, or LISP?
> You need to use a language where you can define your own operators. Have you looked at C++, C#, Haskell, or LISP? Or, um, Swift. :) http://nshipster.com/swift-operators/
Which is where much of the Swift "language" is defined... in the standard library.
-Chris