Re: Goto - finally
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Tue, 23 Jun 2009 21:01:55 -0400
Malcolm Dew-Jones wrote:
The Natural Philosopher (tnp@xxxxxxxxxxxxxxx) wrote:
: Jerry Stuckle wrote:
: > Bill H wrote:
: >> http://us.php.net/goto
: >>
: >> Am sure you all probabably knew about it, but I just saw it. Am glad
: >> goto is now in php. Let me get rid of some of these convoluted if()
: >> else's
: >>
: >> Bill H
: > : > And write more spaghetti code.
: > : > In 25 years of writing C and C++, I have NEVER needed a goto.
: > : No one NEEDS one...But sometimes its a neat way out of deep nesting...
: If you actually go back to Turiung, only half a dozen commands are : actually needed in any language.
: Add, subtract, conditional branch, store and retrieve.and a stack pointer.
: Oddly enough, all assembler includes a direct JUMP... because its more : efficient.
Oddly enough, all assembler includes a direct JUMP because it needs an
unconditional jump (I suppose you could argue that this is not needed
because a conditional jump of a test like 1=1 could be used).
As for programming in C, I don't know what kind of programming other
people have done in C but some things are by far easiest in C with goto. Common usages are to break out of deeply nested loops and to model finite
state machines where state change tables are not flexible enough to be
sensible.
Breaking out of deeply nested loops is quite simple without a goto. State machines are also easily handled without goto statements. It's all in how you handle the code.
"C provides the infinitely-abusable GOTO statement, and labels to branch to. Formally, the GOTO is never necessary, and in practice it is almost always easy to write code without it."
- Kernighan & Ritchie, "The C Programming Language
I wonder how many languages pretend not to have goto by allowing multi
level breaking out of loops? I wonder how many people pretend not to be
using goto by returning from the middle of a function?
There is nothing similar between a goto and a return from the middle of the function. One breaks structured programming. One does not.
As a typical example, a quick grep of sendmail shows at least 388 goto's,
one typical usage being to respond to unexpected state changes during the
smtp protocol handling.
$0.10
And you call sendmail a well written program? I don't. It works, but that's about all I can say.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Goto - finally
- From: Malcolm Dew-Jones
- Re: Goto - finally
- From: The Natural Philosopher
- Re: Goto - finally
- References:
- Goto - finally
- From: Bill H
- Re: Goto - finally
- From: Jerry Stuckle
- Re: Goto - finally
- From: The Natural Philosopher
- Re: Goto - finally
- From: Malcolm Dew-Jones
- Goto - finally
- Prev by Date: Re: Goto - finally
- Next by Date: Re: Goto - finally
- Previous by thread: Re: Goto - finally
- Next by thread: Re: Goto - finally
- Index(es):
Relevant Pages
|