Live data from Hacker News

Remove the ++ and –- operators

github.com

191–200 of 249 posts

Re: Remove the ++ and –- operators

#191
post #154
post #140

Earlier quoted context omitted.

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

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.

Re: Remove the ++ and –- operators

#192
post #135
post #123

Earlier quoted context omitted.

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.

These days yes. But when C was first being developed, when you might have had 64K of memory for everything? Back then it might have been a sane choice.

Re: Remove the ++ and –- operators

#193

I've never understood the obsession with avoiding ++ and --. Douglas Crockford advocates the same thing. All of the examples of why it's bad are contrived and set up to fail. In the majority of real world instances, it's just us incrementing or decrementing a single variable.

All the examples where they're useful are contrived.

And simplicity is an actual goal of computer language design.

Re: Remove the ++ and –- operators

#194

"Drop one of x++ or ++x. C++ programmers generally prefer the prefix forms, but everyone else generally prefers the postfix forms. Dropping either one would be a significant deviation from C." Funny given the name of the language.

Actually it's a good name. C got incremented, and we keep original C locally while some weird side effects no one really wanted keeps happening in committee until the end of time.

Re: Remove the ++ and –- operators

#196
post #180

Earlier quoted context omitted.

I write literally no German in code, but sometimes use it online. And I seriously couldn’t work without the international layout - using proper Unicode characters in my comments is just non-negotiable. If developers would have thought more about localization, and made less dumb assumptions... But there are even minecraft mods that don’t work on QWERTZ, because they are hardcoded to keys that are dead keys on DE layou…

I press alt+shift and can switch between EN-International (which allows easy typing of é, è, ç, etc.) and EN-US (which doesn't easily allow them to be typed). Therefore in EN I can {code} and then alt+shift and {comment with proper Unicode characters}. My suggestion would be to have a setup of T1/EN. Code in EN and comment in T1. Sorry if I'm not being clear or if I'm being confusing... >If developers would have thou…

Well, I actually modded the mod myself – and just made it use Minecrafts' integrated keybind tool.

And switch EN and T1 is not very useful. I’d have to relearn blind typing completely again.

Re: Remove the ++ and –- operators

#198

I disagree with almost all of the justifications, but I don't use Swift and mostly program in C++ so I'm pretty biased. > These operators increase the burden to learn Swift as a first programming language - Same could be said about almost any other slightly "advanced" feature. Not to mention the fact that I fail to see the difficulty here. Increment/decrement take literally a few minutes to explain and understand. Ac…

Its funny, I was just performing an evil whiteboard coding question.

My question involves a sorting function and thus thinking of a problem one step at a time. Start with an inspection, then based on the element perform an action, then marking some bounds with pointers to spots within array.

Since you're doing this one item at a time, you're always just going to be incrementing or decrementing once.

Even if I do a

   for a in range(15): 
in python. Within that loop, I'm doing an action on one item. If I'm counting I'm most probably counting by 1.

We do things all the time in coding by looking at things one at a time, that's why increment and decrement by 1 is so useful to me.

In this case, the candidate couldn't not understand how to increment a "pointer" by one and wanted to solve it with a list. They still figured it out, but it got me thinking of this and maybe we're moving away from really thinking of things one step at a time. To me, its a very useful skill, and the reason I ask the question.

Re: Remove the ++ and –- operators

#199

Go’s compromise here is that these operators are statements, not expressions. There is no return value. This makes it semantically identical to i += 1. It keeps some sugar while removing some classes of gotcha.

Just having `i += 1` would seem more in line with Go's professed Simplicity philosophy. When both `++i` and `i += 1` mean the same thing, you might as well drop one of them. `++i` (and/or I guess `i++`) is barely syntactic sugar.

Agree they could have done without it entirely.

Re: Remove the ++ and –- operators

#200

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

I think forcing me to use "+=" in Ruby reminds me that it's really a method call (which can be overridden), rather than an increment operation on primitive types.

++ and -- (both versions of each) would end up being method calls as well in Ruby or Python. They're even overridable in C++.
Post reply on HN