[Tutor] Multiple exits in a function...

Alan Trautman ATrautman at perryjudds.com
Fri Oct 24 15:43:02 EDT 2003

<snip a lot>
I really don't see what's wrong with multiple returns,
especially in a simple function like this. To me, the
first one is more clear. For this function in
particular, wouldn't the first one terminate first
because it doesn't have to go through the entire list?
Daniel Ehrenberg


You are correct in that you can optimize a function to go faster using
methodology. My perspective is that of maintaining and updating software. If
there are say, 4 exit points at various intervals, to determine what the
return location and value. This means I have to plow through every line of
every function to locate every possible action. If you program a single exit
I only need trap at one point in every function.

In a small one off I probably wouldn't care but I waste a lot of man hours
finding a little known (more than 3 months since it was written) exception
that is blocking a new feature. Insert preachy premature optimization plug
here too;)

There are times; menu systems and speed sensitive apps where this is not
appropriate but most apps on modern computers it is better to waste 50 clock
cycles all the time than to make it take 3 times as long to upgrade or

Ok this is all opinion and I wish I had my old text book now to give you
some other references but I'm supposed to be working:)


More information about the Tutor mailing list