Live data from Hacker News

Remove the ++ and –- operators

github.com

61–70 of 249 posts

Re: Remove the ++ and –- operators

#61

Removing ++ et al: ok, they have their problems. But retaining x += 1? That one has always annoyed me. Why does '+' (and friends) get this special form, but not my functions? Just because they're built-in. They are useful; no argument there. Largely because 'x' can be a complex reference, and you don't have to type it twice (and the compiler doesn't have to figure out that its the same expression twice). E.g. x=x+1 i…

>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?

Huh. C++? You can overload operators, but define your own? I must have missed something.

Re: Remove the ++ and –- operators

#62
While I agree that having both pre- and post- versions is confusing overkill, ++ is no more sugar for x += 1 than x+x is sugar for x*2.

Increment is the fundamental operation, += is sugar for repeated incrementation, not the other way around.

Re: Remove the ++ and –- operators

#63

Earlier quoted context omitted.

Do really think the complexity of pre/post-in/decrement is on the same level as pointers?

I think the added complexity to added value ratio is worse for pre/post-in/decrement operators than it is for pointers, even if the added complexity is less.

Yes - or in the Apple ecosystem, method swizzling is incredibly useful but also incredibly harmful - both to performance through necessitating dynamic dispatch, and to confusion, because WTF, method swizzling?

Re: Remove the ++ and –- operators

#64

We don't have `++` and `--` in Rust either, and I really don't mind. The amount of times I've went to do a `++` where a `+= 1` was clutter has been perhaps one or two times. Then again, my most common use for `++` was `for (;;) {}` index, and we have better in these new languages like Rust and Swift. There are millions of people in this world trying to learn to code and understand the layers upon layers of cruft and…

Oh, I've just closed a Haskell window, saw the title and thought "how would I concatenate strings?", but I'm digressing...

But no, not only for for(;;). There's also the too common array traversal:

while(something) a[x] = b[x++];

And lots and lots of ugly but useful uses in pointer arithmetics where they make things clear. They have no place in any other language, but I'd really miss both operators in C.

Re: Remove the ++ and –- operators

#65

I strongly disagree with this. Being able to do a very simple task like increment or decrement a number inline is useful and reduces clutter and I've always found the idea that the operator complicates things ridiculous. The way they work has always been obvious to me since I first learned to program in PHP as a tween.

They're obvious but only after you've learned them (compare it with x// if you saw that for the first time?).

If readability matters then the rationale that x += 1 is more readable than x++ is very reasonable.

Re: Remove the ++ and –- operators

#66

I strongly disagree with this. Being able to do a very simple task like increment or decrement a number inline is useful and reduces clutter and I've always found the idea that the operator complicates things ridiculous. The way they work has always been obvious to me since I first learned to program in PHP as a tween.

  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.

Re: Remove the ++ and –- operators

#67

Earlier quoted context omitted.

Yes. Anointing "+ 1" as a thing that needs special syntax is weird .

> Yes. Anointing "+ 1" as a thing that needs special syntax is weird. Its not a special syntax for "+1", its a special syntax for the combination of assignment and increment/decrement. The postfix versions (increment/decrement variable and then return the value that was present before the increment/decrement), particularly, are equivalent to: _x = x; x += 1; _x In an environment where that pattern of operations is co…

Sorry, you are correct - although I would restate my point with "+= 1" isn't special.

1 is just another number, the fact that it's useful for enumerating arrays in C isn't relevant as Swift provides more native solutions for that, the use of which should be encouraged.

Re: Remove the ++ and –- operators

#68

Removing ++ et al: ok, they have their problems. But retaining x += 1? That one has always annoyed me. Why does '+' (and friends) get this special form, but not my functions? Just because they're built-in. They are useful; no argument there. Largely because 'x' can be a complex reference, and you don't have to type it twice (and the compiler doesn't have to figure out that its the same expression twice). E.g. x=x+1 i…

Other way around; z = x + y is a shorthand syntax for

  z 
But you're otherwise right, it's annoying that this shorthand syntax isn't more generally available for user functions.

Re: Remove the ++ and –- operators

#69

I strongly disagree with this. Being able to do a very simple task like increment or decrement a number inline is useful and reduces clutter and I've always found the idea that the operator complicates things ridiculous. The way they work has always been obvious to me since I first learned to program in PHP as a tween.

++ is a rare situation since the introduction of foreach. For example in the JVM checking for null would deserve an operator.

Re: Remove the ++ and –- operators

#70
Good, I always sticked to += 1 because it felt better. Weird to see I'm not alone.

I could never really memorise the difference between i++ and ++i because it just seemed like such an obscure thing to have. It's really really weird (and cool) to see someone suggesting removing it.

Post reply on HN