On the other hand, Knuth, among others, claim that "premature optimization is the root of all evil", for a few reasons:
- You can easily waste more time and money optimizing code than you will save in running it
- Optimized code often has a funky, fragile structure that is hard to modify or generalize down the line.
- Optimized code is often hard to read, and/or things are done in inexplicible ways.
Yes, good points, although I'd change the 'often' of the second and third points to 'sometimes' - assuming we talk about Perl here, and not C or assembler. Note however that these points all deal
with full programs, probably running in production, and
created while being paid.
Because of these problems, we should not encourage novices by indulging in such 'evil' speed optimization challenges.
That's a conclusion I don't want to draw. Typically the
challenges presented here and in other forums are about a
small piece of code, that's isolated from their context.
I think that playing around with a small piece of code,
trying out alternatives, consider what they do, without
the burden of context is an
excellent way to understand a language better.
Abigail