60
Emacs
7y

What if I prefer +=1 instead of ++ ?

Comments
  • 9
    variable = variable + 1;
  • 10
    Python won't hate you
  • 25
    var incrementor = 1;

    newVariable = oldVariable + incrementor;
  • 3
    @DeSaboteur get an avatar, you have the required 10 points.
  • 4
    @DeSaboteur You made your incrementor a var. Thus, you're missing the incrementor's incrementor.

    Otherwise... I bet const is a better fit for this.
  • 3
    OCaml dev would prefer incr
  • 1
    @DjSall Will do that right away! :D
  • 2
    AirBnB ESLint preset actually prefers +=1 too
  • 3
    Make a group about how real programmers use +=1 and everyone else is shit. That's what personal preferences are for.
  • 5
    LD A, YOURPREFERENCE
    INC A
  • 1
    const int one = 1;
    int increment = increment + one;
  • 0
    @Tobyvw he is a js developer probably.
  • 16
    var -= -1
  • 1
    // some sort of PHP/JS pseudo-code (sorry!)

    class Increment () {
    public function __constructor(int nb) {
    this.increment = nb;
    }

    public function increment(int nb) : int {
    return nb + this.increment;
    }
    }

    var increment = new Increment(1);
    echo increment.increment(1);

    Should be efficient. Could add some getters and setters and make increment () private

    🤤
  • 2
    It could make a difference when looking at it from an assembly point of view. Some architecture types have dedicated instructions for `++i` and `i++` so in these kind of situations you'd need one instructions, while `i += 1` actually is a register load, add immediate, register store. However a compiler will sort that out for you so don't worry (:

    Tjat's the power of abstraction. Use what ever you feel like!
  • 5
    temp = 1
    while (temp != 0) {
    carry = variable & temp
    variable = variable ^ temp
    temp = carry << 1
    }

    Because arithmetic operators are for noobs
  • 1
    I agree with you, take my +=1 !
  • 0
  • 0
    I also happen to prefer += 1.
  • 0
    Then u r using python
  • 0
    What about:
    variable = variable + (variable / variable);
    (?)
  • 0
    @Archer04
    What about:
    0
    ?

    😂😂😂
  • 0
    @rhein7 or may be
    variable = variable + (variable % (variable -1));
  • 1
    var foo = 1;
    foo = foo + +true;
  • 0
    Its simple. You will get to put a rant and some x+=1 ++'s.
  • 1
    You guys just multiplied by two my ++s thanks 😘
  • 0
    @Emacs you mean shifted left by one :P
  • 0
  • 0
    @Archer04 does @Vim even exists ??
  • 0
    @Emacs nope, you should create it and use it as and alter-ego account :p
  • 0
    All you guys are doing it wrong!

    var varObject = {
    var1: 0
    }

    function incrByOne(varName){
    varObject.varName = varObject.varName × 1;
    }

    IncrByOne("var1");

    //obvs sarcasm
  • 0
    Actually, I'm kind of worried that nobody suggested a TAS or CAS with an atomic integer. What if you run your program using multiple threads?
  • 0
    Then you prefer 4 chars over two.

    Yes, 4. My auto-formatter just inserted a space between = and 1.
  • 1
    fun add(a:Int) : (Int) -> Int {
    return { b: Int -> a + b }
    }
    val addOne = add(-1*-1*-1*-1*-1*-1*-1*-1)
    x = addOne(x)
Add Comment