[Tutor] Simplicity vs. Speed

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 15 May 2001 00:49:27 +0200


On  0, Phil Bertram <phil.bertram@clear.net.nz> wrote:
> Would you suggest that a new programmer just keep things simple so as to
> get the code working bug free, and not worry at all about speed ?

Programmers, even very experienced ones, have misguided intuitions about
where the bottlenecks in their programs are. Besides, sometimes you spent
ages optimizing the snot out of a program, until you decide you want to
redesign it completely, throwing all that work out of the window.

In my opinion, it should work like this in most cases:
- Make the simplest thing that could possibly work.
- *If* this turns out to be too slow, *find out what slows it down*.
- Try to find out a better algorithm.
- Repeat.

Only when you know your algorithm is optimal, and it's still too
slow to use, can you go looking for low level optimizations - but usually
that means finding out what uses most of the time (with the profiler) and
implementing that in C. Personally I've never needed to do this yet.

So worry about speed only once you know speed is a problem.

-- 
Remco Gerlich