|
Boost : |
From: Ed Brey (brey_at_[hidden])
Date: 2000-10-11 10:38:19
From: "Gary Powell" <Gary.Powell_at_[hidden]>
> You know this swamp we started to drain could be fixed by a very smart
> compiler. One that noticed that either the return value was used or not
and
> then do the smart thing...
If the return value is unused, why would a programmer use postfix notation
in the first place? He could just reorder the code to put the increment
after whatever he wants to precede it.
In the case of code like "for (J j; j !=i; j++)", this is just a case of
calling the wrong function (should use ++j). If the programmer chooses to
use a heavier-weight construct than is needed, he should expect to pay a
performance penalty. For example, no one is calling for the compiler to
realize the programmer could have done just fine with a vector, even though
he chose a deque. The bad habits that built up over the C years when it
didn't matter shouldn't influence expectations of new code using new classes
that overload the operators. It's one thing to ask the compiler to perform
an optimization when it makes the programmers life a lot easier, but in this
case, prefix and postfix are equally easy. Moreover, always using prefix
except when you explicitly need postfix makes code easier to read because
intent can be gleaned more quickly.
Hopping-on-the-tag-line-bandwagon-ly yours,
Ed
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk