4 ms·
But it's not BS. If you could use one or the other, so this isn't "a[i++]" or whatever, you should always use the prefix version, particularly if you're operati
by to3m 10y ago
But it's not BS. If you could use one or the other, so this isn't "a[i++]" or whatever, you should always use the prefix version, particularly if you're operating on a non-primitive type.
Assuming the two are written sensibly, and you don't have a Sleep(1000000) in your prefix version or something, the best case is that the two perform the same. The worst case is that the compiler can't spot that the result of the postfix version can be ignored, and the postfix version is then a bit less efficient.
I'm not saying this is likely to end up being the bottleneck in your program... just that choosing ++it is +EV.
I suspect lots of people use it because they learned it that way and now it's been blah blah blah years and it's too late to change. But for some reason, they don't want to admit this, so they come up with spurious reasons for changing being the wrong thing. Which is odd, because when the two would be equivalent, force of habit is basically the only good reason to prefer it++ over ++it.
- gruez 10y ago> just that choosing ++it is +EV Sounds like pascal's wager
- Retra 10y agoPascals Wager is about assuming the EV is infinite, not that it simply exists.
- gruez 10y agoThat's why I said "like". They're both in that you're choosing the option with the +EV rather than the one that the evidence points to.
- mikeash 10y agoThe error in Pascal's Wager is assuming there are only two possibilities. Once you realize that there's the possibility of a God who, say, punishes all the faithful, the argument falls down. That's not the case here. There are actually only two alternatives.
- Retra 10y agoThe only reason you'd have +EV is if evidence suggested it to be so. You compute EV using evidence, and if you don't have any evidence, you don't have any EV at all.