Grant Edwards wrote:
On 2005-04-21, Sergei Organov <[EMAIL PROTECTED]> wrote:


Well, I'm writing for embedded realtime systems in C/C++ and
have never encountered a single need to use goto.

I have encountered situations in C programs where the best thing to use was a goto. Those situations have always been handled beutifully by a "raise" in Python.

setjmp/longjump?

I've always found setjmp/longjmp much more confusing and hard to maintain than a simple goto. It also requires library support that goto doesn't.

Agreed. The 'goto error' idiom is in fact the only goto usage I do agree with provided there is no support for exceptions, but that's not applicable to Python anyway.


Exactly.  I've been writing C code for 20+ years, and the only
problems where I found goto to be a good solution are the ones
where exceptions are even better solutions in Python.  I've
never found myself wishing for a goto when writing Python code.

I can remember in the early apple2+ days of trying to untangle code written by others with liberal use of gotos and no clear program structure. A non trivial task that often meant it was easier to start over than to modify someone elses program. Determining the context of a statement often required snaking through several dozen gotos with 'line number's to find out what a particular section of code actually did. Making changes to such code could be difficult and often had unintended consequences.


The if, elif, else, functions, and while statements are the replacements for goto's. And they make the code much more readable and understandable than something like ...

        100 PRINT "HELLO"
        105 INPUT ">> ";S$      
        110 IF S$ = "GOODBYE" THEN GOTO 140
        115 IF S$ = "HOW ARE YOU" THEN GOTO 150
        130 GOTO 100
        140 PRINT "GOODBYE"
        145 GOTO 200
        150 PRINT "I'M FINE"
        160 GOTO 105
        200 REM CONTINUE

LOL, I HAD TO... Oops caps... look up apple soft basic to remember what I couldn't do. Part of the reason for the spaghetti code was that with line numbers it's easier to tack on something to the end than it is to change all the line numbers if you didn't allow for room. I for one, don't miss goto's or line numbers! ;-)

Apple Soft Quick Refrence -
        http://www.cosmicwolf.com/AppleII/applesoft_basic.htm

Cheers,
Ron
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to