3 ms·
Why not leave those operators for more "advanced" users? I also contest "++" and "--" operators are seriously tripping up "beginners". In most programming book
by Alupis 11y ago
Why not leave those operators for more "advanced" users?
I also contest "++" and "--" operators are seriously tripping up "beginners". In most programming books, it's taught a few chapters in...
- syncsynchalt 11y agoBecause they can constrain the design of the language, and make it more complex to reason about the language. Look at the language necessary to explain their pitfalls in the C standard, or the extra copy needed in operator++(int) to support post semantics in C++. They also make the tools that consume that language slightly more complex. It doesn't sound like much, but in aggregate it's the difference between writing a parser for Java vs. a parser for C++.
- cballard 11y agoBecause non-advanced users will incorrectly abuse them. That's why ARC doesn't let you call retain and release manually, even though there's no technical reason it couldn't.
- JustSomeNobody 11y agoSo? Advanced developers abuse languages all the time. This isn't a valid argument.
- cballard 11y agoMaking the language difficult for advanced developers to abuse is practically an explicit goal of Swift. I mean, its predecessor allowed you to mutate your class hierarchy at runtime, and this was a thing that people commonly did! "You can't do that" is a powerful tool for making code safer.
- Alupis 11y ago> Because non-advanced users will incorrectly abuse them. I don't see how this is a valid reason to remove the operators completely. Beginners will get it wrong sometimes, so we should remove it? Beginning users are likely to make all kinds of errors, so the implication would be maybe we should remove the entire language...? Not to mention, pre-decrement and post-decrement are not complicated concepts. There are many valid reasons to use both, although post-increment/decrement seems to be the more common use.
- cballard 11y agoWell, 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.
- davrosthedalek 11y agoDo really think the complexity of pre/post-in/decrement is on the same level as pointers?
- dragonwriter 11y agoI 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.
- cballard 11y agoYes - 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?
- deleted 11y ago[deleted]
- Alupis 11y agoI 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 argue to remove pointers from C, since you can optionally not use them. If you don't need that language construct in your program, don't use it. But leave it for others who do want/need it.
- lmm 11y agoReading 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.
- Alupis 11y ago> 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 clever to define constants for this so now you'll get "x += INCREMENT_VALUE", making you have to go lookup whatever "INCREMENT_VALUE" is, etc...
- lmm 11y ago> 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.
- Alupis 11y agoI 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 against "++", might as well go all the way back to BASIC days and only allow "x = x + 1"
- Retra 11y agox = 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.
- andresmanz 11y agoBecause beginners could get confused when seeing the operators in other people's code, for example. I remember the day I first saw a '++'. It was a rainy night, and I was inspecting a colleague's for loop, when suddenly a '++' operator appeared. I asked myself, "What in the holy bacon of Zeus is that?" So I looked it up in my book. My head almost exploded, and I asked myself if I should quit programming immediately. It was simply too complicated. After four months of agony and pain I finally recovered and started programming again. And yet... Sometimes, when it's raining outside, the memories come back. Programming... No, my life will never be the same again.
- jakejake 11y agoI'd hate to think what would happen if one were to run into a ternary operator!