@thistooshallpass said:
Well you don't really ignore the [alleged] dodge if you mention it... which raises the question of who is the sly one here...
It's true, I am known to be rather sly.
@thistooshallpass said:
On the actual point, I still don't agree with your syntax because the same token presents a different behavior in a different context, and I don't need to dig google urls to back something that obvious. (is he pre-incrementing the value? oh no, it's in a for loop, so he is cleverly not clobering the variable!).
So, the point of the style guide I linked isn't just the "obvious" difference in semantics in itself, but rather the consequences of the difference in semantics. In particular, the "++" operator is often used for iterator semantics over expensive data types, say for selectively loading pieces of a huge file into memory. Pre-increment gets to do a straight-up write into an existing memory block, while post-increment necessarily requires two segments to be live simultaneously (even if the old one soon gets discarded thereafter); in many real cases, this could result in L1/L2 cache eviction and/or page faults which non-trivially degrade performance.
I should clarify as well, when I review code I don't actually care if people prefer post-increment, unless it is indeed a case where they are using some expensive iterator type. It's just that your particular claim that post-increment is preferable over pre-increment due to the latter being "non-typical" syntax is unfounded for several reasons:
- Based on the style guide I linked, plus the responses in this thread, pre-increment is clearly not "non-typical".
- Pre-increment is the one that is "sometimes better, but never worse" than using post-increment, so if anything, pre-increment should be preferred over post-increment.
- Performance considerations aside, the very meaning of pre-increment ("increment the thing") captures the intention inside the for-loop better than post-increment ("give me the current value, and then increment the thing").