Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Tobyvw6987y@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. -
CWins48087yMake a group about how real programmers use +=1 and everyone else is shit. That's what personal preferences are for.
-
Phlisg25167y// 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
🤤 -
Wack61917yIt 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! -
Ezard19607ytemp = 1
while (temp != 0) {
carry = variable & temp
variable = variable ^ temp
temp = carry << 1
}
Because arithmetic operators are for noobs -
All you guys are doing it wrong!
var varObject = {
var1: 0
}
function incrByOne(varName){
varObject.varName = varObject.varName × 1;
}
IncrByOne("var1");
//obvs sarcasm -
Wack61917yActually, 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?
-
Then you prefer 4 chars over two.
Yes, 4. My auto-formatter just inserted a space between = and 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)
What if I prefer +=1 instead of ++ ?
devrant