In the Absence of a GoTo Statement: Newbie needs menu-launcher to choose amongst sub-programs

Alex Martelli aleaxit at yahoo.com
Sat Apr 14 03:20:19 EDT 2001


"Ron Stephens" <rdsteph at earthlink.net> wrote in message
news:3AD67012.8EE5E90C at earthlink.net...
> Hmm, thanks! But now I worry myself, if "GoTo" was good enough for Donald
> Knuth...then why isn't it good enough for me??? And, is it therefore
possible that

Actually, Donald Knuth, in his brilliant and provocatively titled
"Structured
Programming with Goto Statements", showed exactly the loop-structure a
high-level language would need to let goto's be avoided without any cost
(he was very worried about performance, of course): it's called the "N and
a half times" loop, and in Python you generally get it with a 'break'
statement.

Python's break is not as general as, say, Java's, so that you will need a
slightly less readable try/except in certain nested-loop cases; however,
as, in Python, performance is not the main goal, we normally structure
programs into small functions and rarely nest things too deeply -- nesting
breeds complication, and good Python style targets simplicity.

Exceptions are the missing piece of the puzzle, by the way -- the reason
we don't need 'goto' any more for error-handling.  Exceptions structure
error-handling very effectively.

> the whole crusade against "goto" is just an irrational fad??/ Are we
persecuting

Nah, it's about moving our mental model of computation away from
the "machine's innards" levels and towards more abstract ones.  If
you program in machine language, you will of course use conditional
and unconditional jump instructions.  Modern languages are a long
way from that.  The so-called "high-level" languages that Djikstra,
Knuth &c were discussing in the '60s and '70s were a mid-way stage,
whence the debates about appropriateness of various low-level
constructs.

"If you want machine language, you know where to find it" (e.g.,
Knuth's beautiful books:-).  Python is not machine language and
it would be folly for it to try to mimic such low-level approaches.

> ourselves for no good reason??? Will future generations of computer users,
in the
> year 3000 A.D., look back and view our forswearing of the most usefull
"goto"
> statement, as equivalent to how we view Islamic folks beating themselves
with whips
> in a religious frenzy???

I suspect you're confusing Islam with Catholicism here -- flagellants
are a typical Catholic phenomenon, while I think typical Islamic
'frenzy' practitioners are the Sufi "whirling dervishes" (a form of
'movement meditation' which has interesting aspects indeed).


Alex






More information about the Python-list mailing list