31 ms·
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 fou
by homulilly 11y ago
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.
- ra1n85 11y ago"These operators increase the burden to learn Swift as a first programming language" It looks like they may be trying to make it easier for current tweens that would have otherwise learned PHP. Don't see the value in this. These operators are terse, well known, and are implemented in a wide array of languages.
- JoeAltmaier 11y agoWell known for old timers. But some folks have an actual issue understanding them. For those of us that are comfortable; fine, no issue. But they are a little strange; the order of operations in a complex expression can be hard to tease out for novices. Are they worth it?
- Nadya 11y agoWhat about for beginners like me who instantly understood `++` and `--` as increment/decrement but avoided `+=` and `-=` for being rather nonsensical? This half-reeks of something that a professional/advanced user thinks trips up beginners without actually tripping up beginners. Or they have an anecdotal sample size of n < 10 and decided since it confused 1 person that 10% of people get confused.
- cballard 11y agoApple has a long history of readability over terseness. "plus plus" doesn't mean anything. It might even be confusing that it doesn't add 2.
- dstanko 11y agoFrom Swift documentation: for i in 0..<count { print("Person \(i + 1) is called \(names[i])") } 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...
- deleted 11y ago[deleted]
- cballard 11y agoI would implement that like: zip(names, 1...names.count).forEach { name, index in print("Person \(index) is called \(name)") } Or, in an ideal world: zip(names, 1...names.count) .map({ name, index in "Person \(index) is called \(name)" }) .forEach(print) Currently, that isn't valid Swift, "print" can't be used like that, though if you define a closure it works: let printIt = { x in print(x) } zip(names, 1...names.count) .map({ name, index in "Person \(index) is called \(name)" }) .forEach(printIt) I think that Swift could use = for equality, since assignments return Void and comparison returns Bool. Maybe it should. But your argument boils down to "if you can't be clear everywhere, don't be clear anywhere". That's not a good goal.
- dstanko 11y agoMy argument ultimately "there are better things to do". At the same time, interpreting ++ as add-add is certainly not an argument. You can say that you don't like infix and postfix operators, but not whether they are readable. If you consider readability, then why !a instead of not(a)? Why || instead of or?
- Shish2k 11y agoSpeaking as somebody who has no idea what X..<Y means, I assume it means "start from X and carry on for as long as you are less-than Y"? Is that correct? 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"...
- josu 11y agoPlus a relatively easy concept to understand even if you encounter them for the first time. I'd say that it's even more intuitive than +=.
- svisser 11y agoThey'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.
- myth_buster 11y agoI'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.
- homulilly 11y agoSeems more like an idiot test to me. If someone legitimately finds something this basic confusing they are going to constantly be running into problems and aren't suited for a programming job.
- roninb 11y agoThere are also interview questions asking you to write FizzBuzz. That doesn't mean all loops are ambiguous and complex. Being an interview question doesn't really mean anything other than it being an interview question.
- tajen 11y ago++ is a rare situation since the introduction of foreach. For example in the JVM checking for null would deserve an operator.
- kuschku 11y agoOMG, yes! maybeNull?.getContent()?.toString() This would improve my coding sooo much. Currently I use Optional.fromNullable(maybeNull).orElse(new DummyObjectThatReturnsNullOnAllMethodCalls).getContent(), and then repeat the process.
- DiThi 11y agoI use "?" constantly in coffee-script. And while I missed ++ for a while in Python, I don't use it in coffee even though it's available.
- caoilte 11y agoWould rather they started down the road of getting rid of null.
- tajen 11y agoI was talking about the JVM. ;)
- asddubs 11y agoCoincidentally, I've had a little discussion with a non-programmer friend of mine about this operator the other day. He does a little scripting in a game maker program sometimes, and told me that the ++ operator confused him way more than it ever helped him, because he keeps typing stuff like "x + 7" instead of "x = x + 7"
- vvpan 11y agoAlmost 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.
- CamperBob2 11y agoPublic 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.
- brianberns 11y agoYou might enjoy ++C, though.
- whoopdedo 11y agoI'm just perturbed by how many people are describing x++ as equivalent to x+=1
- fao_ 11y agoThat'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.