5 ms·
> but sometimes it's nice to make a habit of doing things the faster way when you have two choices that are otherwise indistinguishable. That is virtually neve
by gnaritas 9y ago
> but sometimes it's nice to make a habit of doing things the faster way when you have two choices that are otherwise indistinguishable.
That is virtually never the case.
> For example I try to use ++x instead of x++
Those have wildly different semantics.
- colejohnson66 9y agoYes, but if used as their own statement and not used as some bigger expression (parameter to function, etc.), any decent compiler will compile them the same way.
- gnaritas 9y agoYes, and thus a perfect example premature optimization; semantics should define default usage, not some possible micro optimization. This is exactly the kind of case Knuth is talking about, going around doing ++x because you think it's faster when the standard idiom is x++ is premature optimization.
- marcosdumay 9y agoWell, there is no reason for any standard idiom there. Those `++` and `--` operators are something to avoid anyway.
- zerr 9y agox++ is not the "standard idiom".
- jcelerier 9y agoNotice how the asm changes here if changing it++ to ++it: https://godbolt.org/g/W5w7Dc https://godbolt.org/g/W5w7Dc