Krazy: prefix vs. postfix ++ and -- operators
Andreas Pakulat
apaku at gmx.de
Tue Jan 11 15:24:18 GMT 2011
On 11.01.11 16:16:23, Christoph Feck wrote:
> Krazy says:
>
> "You should use ++ and -- as prefix whenever possible as these are more
> efficient than postfix operators. Prefix increments first and then uses the
> variable, postfix uses the actual; the variable is incremented as well.
> Because of this, the prefix operators are inherently more efficient."
>
> Considering that today's CPUs have multiple pipelines, using a value directly
> seems faster to me than waiting for it to be incremented or decremented.
>
> Is this krazy warning still correct?
I can't answer that question, but I think there's at least one other reason
to prefer prefix over postfix. That is that prefix has no side-effects or
'surprises' when beginners are looking at the code. So the code actually is
easier to read and understand. So personally I think the krazy-check is
just fine, only the 'why' could need an additional paragraph.
Andreas
--
Your supervisor is thinking about you.
More information about the kde-core-devel
mailing list