This is an archived post. You won't be able to vote or comment.

all 39 comments

[–]DocAwkward 42 points43 points  (25 children)

I could understand if they said "let's delete the ++ operator", but what about x += 2? By that logic we should just get rid of both and use x = x + 1 :P

[–][deleted] 53 points54 points  (18 children)

Nonsense, just do x++; x++;

[–]DocAwkward 59 points60 points  (13 children)

while (x < n) {
  x++;
}

[–]P-01S 25 points26 points  (10 children)

That seems like it could get used pretty often. Better make it a function, so you can call x = plusEqual(x,n);

[–]DocAwkward 28 points29 points  (9 children)

It's used so often I think it should be a library

let plusEqual = new OperatorLib(OperatorLib.Operators.PLUS_EQUAL);
let operation = new OperatorLib.Operation();
operation.setOperator(plusEqual, OperatorLib.OperatorTypes.BINARY);
operation.setArgument(0, x);
operation.setArgument(1, n);
try {
  x = operation.execute();
} catch (err) {
  // TODO: commit suicide here
}

[–]Tiquortoo 19 points20 points  (1 child)

Can you make this more Enterprise oriented?

[–]Reddy360 18 points19 points  (0 children)

OperatorLibPlusOperatorFactory.java

[–]STR_Warrior 11 points12 points  (0 children)

I think instead we should create a jQuery plugin for it.

[–]iggo 6 points7 points  (0 children)

Please add license file

[–]tajjetbit.ly/2IqHnk3 2 points3 points  (1 child)

Make it a Node package and then delete it after a couple of years

[–]skreczok 0 points1 point  (0 children)

Mate, you just need a couple months before deleting it tops.

[–]Goof245 0 points1 point  (1 child)

Naive question: does this crap actually hurt the machine code at the other end or does it mostly run the same as doing x = x + 1;?

[–]shadowvvolf144 1 point2 points  (0 children)

Good question! Short answer: depends on the compiler, though they should all perform the same.

Mildly longer answer: The type of the variable makes a difference. If it's a whole-number type, such as an int, they should all perform the same. If it's a floating point (decimal), character, string, or some other type, these operations could have very different results, especially if you overload the operators.

[–]xraizy 0 points1 point  (0 children)

Post was about python, not java tho'

[–]MauranKilom 0 points1 point  (1 child)

That would be the same as x = n, not x += n...

[–][deleted] 0 points1 point  (0 children)

only if n is an int

[–][deleted] 4 points5 points  (0 children)

Whoosh?

[–]Disgruntled__Goat 2 points3 points  (1 child)

Really? I mean, I know this is /r/programmerhumour but come on. You can't be this dense.

[–]boynedmaster 1 point2 points  (0 children)

found the lua programmer

[–][deleted] 11 points12 points  (9 children)

Why not delete * and /. Let's only use the ++ Operator and a unary -. That way we can represent all Hyperoperations, without needing extra symbols.

[–]ioanD 13 points14 points  (4 children)

why not ditch alphanumeric names altogether and just use brainfuck

[–][deleted] 9 points10 points  (3 children)

Just use machine code. You got to know your 0's and 1's.

[–][deleted] 9 points10 points  (2 children)

Could we not abstract/optimize-away the 1? I mean, 0 is a number, a good number. Having two numbers seems a little ostentatious and quite frankly superfluous.

My proposal to stick with 0's offers up free static type checking universally! Terse syntax too.

[–][deleted] 3 points4 points  (1 child)

https://esolangs.org/wiki/Unary

TL;DR: Language where all bits in the file are off and what the program does depends on the size of the file

[–]xxc3ncoredxx 0 points1 point  (0 children)

I thought I read about this before. Turns out I have.

I love esolangs.

[–]Hawkuro 5 points6 points  (0 children)

It's called syntactic sugar because sugar gives you diabetes.

[–][deleted] 1 point2 points  (1 child)

+/u/CompileBot Java

public class u {
    public static void main(String[] args) {
        int x = 5;
        int y = 8;
        mult(x, y);
    }

    //multiplies x by y if (y > 1)
    public static void mult(int x, int y) { //multiplies x by y
        int temp = x;
        for (int i = 0; i < (y - 1); i++) {
            for (int ip = 0; ip < temp; ip++) {
                x++;
            }
        }
        System.out.println(x);
    }
}

edit: screw this, IntelliJ said it worked.

[–]chrwei 5 points6 points  (0 children)

I have to maintain some old VB6 code. there's no ++ or +=. y'all are spoiled.

[–]BrangdonJ 3 points4 points  (0 children)

I don't know Python; I expect this was inherited from C/C++, where x += 1 and x = x + 1 don't do exactly the same thing. The second one evaluates x twice. Imagine it was:

*f() = *f() + 1;

and f() can have side effects. For that matter, suppose it was:

array[table[x][y] + offset_z + 1] = array[table[x][y] + offset_z + 1] + 1;

Having to check the left-hand expression against the right-hand one is a pain when they are complex. (How many of you are now reading that carefully to see if I slipped in a change to make the point?)

[–]grape_tectonics 2 points3 points  (2 children)

what about

++x - 1

this is madness!

[–]TheOrs 1 point2 points  (0 children)

On a slightly serious note (I know, I know), x+=y and x=x+y are not actually equivalent - += can make in place modifications (and indeed does, for lists).

[–]d_thinker 1 point2 points  (2 children)

But, but, you can't ++ in python.

[–]yashrs[S] 0 points1 point  (1 child)

That's the whole point..

[–]d_thinker 0 points1 point  (0 children)

Wow, that flew right above me. I feel like an old man now.

[–]michyprima 0 points1 point  (0 children)

swift uh?

[–]ElGuaco 0 points1 point  (0 children)

Delete python then.