Reinhold Birkenfeld wrote: > John Bokma wrote:
>>>praba kar wrote:
>>>> In Python what is equivalent to goto statement
>>>You shouldn't use goto in high-level languages.
> Thank you!
> Above all your claim is well justified. These brilliant arguments
> you have put forth really explain in a magnificent way why goto is a
> sane addition to any HLL.
OK - Here's some reasoning that may illuminate it. We could, in theory,
reduce any language to the minimal Boehm & Jacopini control structures
(iirc there were only four). In effect, anything beyond these is
syntactic sugar. IOW, feel free to use a minimalist Turing Machine
to implement your next 100,000 line program.
I, on the other hand, have a really hard time finding infinite tapes (in
both directions) and a suitably fast tape reader to implement such
ideas. (I also seem to recall that any digital circuit can be
implemented with nothing more than AND and NOT gates, but I'd rather
not, thanks - I don't have enough probes on my oscilloscope to debug
that kind of hardware.)
Control structures/directives evolve to solve real problems. 'goto',
properly used, can actually clarify code, especially when dealing with
exceptions and the like. Oh, we may rename it and call it 'break' or
'try/except' or whatever suits the language author's fancy, but the
concept is similar, if not identical. 'goto' certainly could be
synthesized in Python with the appropriate try/except hierarchy
and custom exceptions, but in many cases this would *really* be overkill -
a simple 'goto' would be considerably simpler *and* probably easier
to understand. Note that I am not arguing for 'goto' in Python,
merely trying to respond to your point about why it is does not inherently
appropriate for HLLs.
Some HLLs almost have to have it by definition. I cut my teeth as programmer
writing for embedded realtime systems in a HLL (PL/M). While you could,
in theory, completely avoid 'goto' in a realtime environment, it would
make all manner of practical programming problems kind of ugly to implement.
BTW, all modern systems come complete with 'goto' implemented in
*hardware* - they're called "interrupts".
More to the point, I have seen some really tortured code written in the
name of maintaining religious purity of some kind ("Structure", "Object
Orientation",...). While language constructs can promote better- or
worse code structuring, at the end of the day, programming is still the
expression of human thought. Some people think clearly, some don't, and
this has little to do with just what language structures are in use.
Python is elegant at almost every level, and I am certainly not
arguing for 'goto' in the language. But to reflexively assume that
it has *no* place in a modern HLL is, I think, a bit overstated.
I must now 'goto' sleep ... and I cannot think of a better way
to express this...
Tim Daneliuk firstname.lastname@example.org
PGP Key: http://www.tundraware.com/PGP/