Live data from Hacker News

Remove the ++ and –- operators

github.com

131–140 of 249 posts

Re: Remove the ++ and –- operators

#131
post #83
post #75

Earlier quoted context omitted.

Well, I type the * key to get a +, then shift and 0 to get a =, then 1 to get a 1. Slow, and my fingers have to jump completely over the keyboard. What is far more annoying, and should be banned, are `these` (I have to press shift+' twice to get one `, otherwise I end up with á' instead of `a`), and {}[], as they are on AltGr+7/8/9/0

Which type of keyboard do you use? I know English-International has a similar issue with `'`, `"`, and `'`. I think QWERTZ or a German keyboard do as well? Can try changing it to English - US to get around that if you run Windows. Not sure about Mac/Linux. I swapped the US out for international because it was important to me to type Pokémon properly. It is an annoyance to have to type ` followed by a space because it…

I use a bastardized DE1 layout, as provided by linux.

So I have æ, but not å.

Actually, I’m gonna switch to DE3.

Still doesn’t solve these special characters.

Re: Remove the ++ and –- operators

#132
post #123

Earlier quoted context omitted.

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

Not necessarily so if you come from a strong Assembly language background. Most processors have a special instruction for incrementing a register that's shorter (and faster) than the more generic ADD instruction. For instance, on a 64-bit x86 machine, ADD RAX,1 is nine bytes long, while INC RAX is one byte. Maybe not as much a win these days, but back when memory was smaller and more expensive, it was worth it.

In a high-level language, this is the job of the compiler, though. If the compiler isn't generating those instructions for cases where the increment can be proven to be 1, I would consider it a bug.

Re: Remove the ++ and –- operators

#133

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…

Do you mean something like "compound assignment operators"? Apparently you can define custom operators like:

    func += (inout left: Vector2D, right: Vector2D) {
        left = left + right
    }
https://developer.apple.com/library/ios/documentation/Swift/...

Re: Remove the ++ and –- operators

#134
post #126

Earlier quoted context omitted.

Well, the same argument can be made for pointers, which are clearly harmful to a safe language. Swift does include them, but puts a screaming "Unsafe" in front of their type names so that it's clear that unless you really know what you're doing, you're probably doing something wrong. There's no way to do that with a ++ operator, so it's being removed.

I didn't know we were making comparisons between Swift and C. Most people would agree C lets the developer do a lot of terrible things (by design, since some of those terrible things are necessary for low level stuff, which C was targeted at). Pointers are confusing for a lot of people. Which is why almost no modern language uses them. Comparing "++" with C pointers is not a valid argument. Even so, I would never arg…

This operator was popularized by C, so comparisons with C make sense. Of course you wouldn't remove pointers from C, the language would barely work if you did.

Confusing C-isms like pointers are what Swift is trying to get away from. This is another case of that.

"We're making a new language, it isn't C, but will share some characteristics. Which should those be?" is the question being asked here.

Re: Remove the ++ and –- operators

#135
post #123

Earlier quoted context omitted.

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

Not necessarily so if you come from a strong Assembly language background. Most processors have a special instruction for incrementing a register that's shorter (and faster) than the more generic ADD instruction. For instance, on a 64-bit x86 machine, ADD RAX,1 is nine bytes long, while INC RAX is one byte. Maybe not as much a win these days, but back when memory was smaller and more expensive, it was worth it.

Nowadays, a compiler that doesn't optimize a "+1" is a bad compiler.

Re: Remove the ++ and –- operators

#136
post #49

Earlier quoted context omitted.

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

Have you never heard the rule that your code should have no numbers in it except 0 and 1? All other numbers should be written as constants instead, and then use the name of the constant instead of the number directly. > Anointing "+ 1" as a thing that needs special syntax is weird. 1 is special.

Yes, of course, I use constants in all cases.

Why is adding 1 to something special, compared to adding 2 to something? The #1 use case, by far, is C-style for loops, which aren't used in idiomatic Swift code.

Re: Remove the ++ and –- operators

#137
post #105

> Their expressive advantage is minimal - x++ is not much shorter than x += 1 Personal opinion, but I definitely miss '++' every time I'm doing '+=' in Python.

Then I take it you don't buy into the Python philosophy of "There should be one-- and preferably only one --obvious way to do it." https://www.python.org/dev/peps/pep-0020/

To me, ++ is the one obvious way to increment. I use for loops constantly and think of incrementation as a different thing from addition.

Re: Remove the ++ and –- operators

#138
post #96

Earlier 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.

You might enjoy ++C, though.

Re: Remove the ++ and –- operators

#139
post #96

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.

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.

That's the fault of the authors, not the fault of the language feature. And IMO I've not really found the difference confusing in practice.

Re: Remove the ++ and –- operators

#140
post #128
post #35

Earlier quoted context omitted.

Reading is more important than writing. If you leave them in they're one more special case that everyone has to memorize before they can maintain someone else's code.

> If you leave them in they're one more special case that everyone has to memorize before they can maintain someone else's code It's literally no different than having to remember what "+=" does... which is what's being proposed as the alternative. > Reading is more important than writing I would agree, but "x++" is not difficult to read. It's more concise than having to read "x += 1". Or worse, beginners will think…

> It's literally no different than having to remember what "+=" does... which is what's being proposed as the alternative.

You already have to remember what "+=" does though. If they kept ++ you'd have to learn both.

Post reply on HN