Wed, 20 Oct 1999 08:45:13 -0500
> > This particular case has nothing to do with optimization. All
> > validated Ada compilers are required to evaluate "static" expressions at
> > compile-time. 2**4 is static, as are essentially all operations
> > involving numeric literals, named numbers, or named constants whose
> > initial value is static. See section 4.9 (or so) of the manual.
How does validation guarantee compliance? If the compiled code has the
right answer, how do you know it was gotten at compile time rather than
> ..... mere mortals who were not involved in writing the LRM are
> often assume they have to do something to make the code fast when in
> reality the compiler was required to do it for them. Sometimes a hand
> rolled optimization is the correct choice but not nearly as often as most
> developers think.
IMHO, an optimization that obscures the code even slightly is appropriate
ONLY when you can prove there is no other way way to satisfy a genuine
timing requirement. And "as fast as possible" is _rarely_ a true requirement.
For example, our recent discussion of "sum of cubes": I posted the least
efficient solution of anybody, and it ran in less than a second. As
examples of how to optimize, the other solutions were excellent. But in
terms of accomplishing a real task, they would have been undesirable.
Especially unfortunate are those "optimizations" that actually make code
slower. And I've seen enough of those in software maintenance to make me
believe "If it makes the code more complicated, there's a very good chance
it makes it slower."
Named numbers do not fall into this category--they make the code clearer
without making it slower.