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.
Remove the ++ and –- operators
91–100 of 249 posts
Re: Remove the ++ and –- operators
#92Removing ++ 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?
Or, um, Swift. :)
Re: Remove the ++ and –- operators
#93> Keep both x++ and ++x in the language, even though they do the same thing. ?
> ?
That was a subalternative underneath the alternative of changing the operators to return Void like other assignment operators. ++x and x++ differ in that the former returns the value after the increment, the latter the value before; if they return void, all they do is the increment with no difference.
Re: Remove the ++ and –- operators
#94Earlier quoted context omitted.
>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
#95> Keep both x++ and ++x in the language, even though they do the same thing. ?
Re: Remove the ++ and –- operators
#96I 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.
Re: Remove the ++ and –- operators
#97I 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.
Being an interview question doesn't really mean anything other than it being an interview question.
Re: Remove the ++ and –- operators
#98Earlier quoted context omitted.
>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?
> 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? AFAIK, Lisp doesn't have syntactically-distinct operators at all just functions which may have names similar to operators used in other languages, and C# and C++ don't seem to support custom operators at all. [0] OTOH, Perl 6 has robust support for c…
Re: Remove the ++ and –- operators
#99"When the return value is needed, the Swift += operator cannot be used in-line, since (unlike C) it returns Void." Why was this decision made?
a += b -= c;
Don't ask me in which order it executes, I would need to read the C standard again and wrap my head around how this case is described therein.
I'm also not sure wether this is defined or undefined behaviour:
a += b -= c *= a;
Re: Remove the ++ and –- operators
#100Removing ++ 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…
In Swift, + and += are just operators. They're two separate operators which happen to do similar things. In Swift, an operator can be defined to mutate its left-hand operand, which += is defined to do. You can create your own operators that do that as well.
If you want to do it for methods, Swift has mutating methods which can change the thing they're sent to. In this case, you'd mark your Xform func as "mutating" and then you can write someComplexThing.Xform(bar) and it will mutate someComplexThing in place.
Of course, if you want to support both forms, you end up with a bit of redundancy as you have to define stuff twice. But the built-in stuff is the same way, and you can at least define one in terms of the other to cut down on duplication.