Re: Beginner Projects



Roedy Green wrote:
On Thu, 30 Aug 2007 00:32:11 -0400, Lew <lew@xxxxxxxxxxxxx> wrote,
quoted or indirectly quoted someone who said :

. OTOH, this counts as "premature optimization" in many cases.

It is simpler code, so I don't count it as optimisation. Optimisation
that gets you in trouble is verbose, harder-to-maintain code. I
figure every student should be familiar with odd/even idiom.

Sometimes it can save you.

int mid = (low + high) / 2;
int mid = (low + high) >>> 1;

The first one breaks when low + high > 2^31-1, the second one doesn't (only when low + high > 2^32 - 1).

In other news, premature optimization only counts IMO when the change involves non-trivial optimizations.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.