11

People can judge you between i++ and i+=1

Comments
  • 2
    You can type i++ a few milliseconds faster than i += 1 ←_←
  • 5
    @PublicByte And yet by writing this you wasted more time than you saved
  • 0
    Also

    void increment(int n) {
    return n+1;
    }
  • 0
  • 3
    @CaptainRant but still... relies too much on the compiler.
    in 98% of the cases, you rather want to use ++i
  • 0
    @s0LA Would it even matter whether it's ++i or i++ if you're not assigning the value to another variable?
  • 4
    @kamen yes.

    i++ returns the variable and then increments it.

    ++i increments the variable and then returns it.
  • 0
    Can also be a sign of when you came up and where, kind of like how some people still religiously put the constant on the left side of comparisons bc C. For this instance, Actionscript for example had cases where i+=1 would be significantly faster after compilation, and cases where it would be slower. Just historical leftovers.
  • 0
    @s0LA Well, at my job I often do i++ without problems, though I did find some cases where i++ was a problem and I really needed ++i, indeed.
  • 0
    @CaptainRant as I mentioned; you won't have problems with because the compiler fixes it for you.
    It's in a debug build a tiny performance problem (we're talking here about 0,0x nanoseconds) but in the end, it usually is expressing something different.
  • 0
    This won't be applied for Python though.
Add Comment