I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine. I put it aside assuming
noone would actually want it, but Wez and Ilia convinced me to post it for
consideration:
Description:
http://pecl.org
Patch:
http://pecl.org/patches/opcode_goto_5.1.0.diff
Talk amongst yourselves...
-Sara
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine. I put it aside assuming
noone would actually want it, but Wez and Ilia convinced me to post it for
consideration:Description:
http://pecl.orgPatch:
http://pecl.org/patches/opcode_goto_5.1.0.diffTalk amongst yourselves...
Oh that's awesome... please say yes... please please please :) I've
always thought goto was a bit of a missing element in PHP since it's the
method of choice IMHO for fast and concise parsing.
Cheers,
Rob.
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
I wrote up a patch for implementing gotos in php scripts a couple months
ago as an exercise in working with the Zend engine. I put it aside
assuming noone would actually want it, but Wez and Ilia convinced me to
post it for consideration:
Big +1 from here. It will signficantly simplify my error handling code :)
If engine guru's don't have technical objections for this patch I think it
should be applied right away!
Edin
The patch looks ok to me.
One issue to be worked out is to prevent goto from jumping out of a
try..catch block.
goto is that nice tool that everyone is brainwashed to believe is
evil, instead of simply being taught how to use it properly.
+10 ;)
--Wez.
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine. I put it aside assuming
noone would actually want it, but Wez and Ilia convinced me to post it for
consideration:Description:
http://pecl.orgPatch:
http://pecl.org/patches/opcode_goto_5.1.0.diffTalk amongst yourselves...
-Sara
The patch looks ok to me.
One issue to be worked out is to prevent goto from jumping out of a
try..catch block.
After you mentioned that in IRC I tried out several test cases each of which
behaved well, but I of course could have missed some possible combination...
Btw, goto labels are considered op_array local, so you can't jump out of one
function into another function, or in/out of the main scope.
-Sara
Goto is an extremely useful for parsers and makes life much easier when
dealing with complex error handling situations.
+1
Ilia
I wrote up a patch for implementing gotos in php scripts a couple months
ago as an exercise in working with the Zend engine. I put it aside
assuming noone would actually want it, but Wez and Ilia convinced me to
post it for consideration:Description:
http://pecl.orgPatch:
http://pecl.org/patches/opcode_goto_5.1.0.diffTalk amongst yourselves...
-Sara
Am Do, den 29.07.2004 schrieb Ilia Alshanetsky um 4:55:
Goto is an extremely useful for parsers and makes life much easier when
dealing with complex error handling situations.
+1
/Georg
Alle 04:55, giovedì 29 luglio 2004, Ilia Alshanetsky ha scritto:
Goto is an extremely useful for parsers and makes life much easier when
dealing with complex error handling situations.
Does a goto operator make sense in a language that wants to be more and more
OOP oriented and that has just introduced a new OOP model? Not so much for
me.
-1
+1
Goto is an extremely useful for parsers and makes life much easier when
dealing with complex error handling situations.+1
Ilia
I wrote up a patch for implementing gotos in php scripts a couple months
ago as an exercise in working with the Zend engine. I put it aside
assuming noone would actually want it, but Wez and Ilia convinced me to
post it for consideration:Description:
http://pecl.orgPatch:
http://pecl.org/patches/opcode_goto_5.1.0.diffTalk amongst yourselves...
-Sara
--
--
Jacques Marneweck
http://www.powertrip.co.za/blog/
Hi,
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine. I put it aside assuming
noone would actually want it, but Wez and Ilia convinced me to post it for
consideration:
I was really rolling on the floor when I saw this mail, because I faked
up such a patch as a joke a few days ago.
I love gotos. Try/Catch is goto for poor people ;)
+2^17,3 from me
Stefan
----- Original Message -----
From: "Stefan Esser" sesser@php.net
To: <"Sara Golemon"@utopia.rusko.us>; internals@lists.php.net
Sent: Thursday, July 29, 2004 6:05 AM
Subject: Re: [PHP-DEV] GOTO operator
Hi,
I wrote up a patch for implementing gotos in php scripts a couple months
ago
as an exercise in working with the Zend engine. I put it aside assuming
noone would actually want it, but Wez and Ilia convinced me to post it
for
consideration:I was really rolling on the floor when I saw this mail, because I faked
up such a patch as a joke a few days ago.I love gotos. Try/Catch is goto for poor people ;)
+2^17,3 from me
tongue out of cheek + my opinion doesn't count,
goto is very useful for error handling when you've got stuff to clean up
that's common between error conditions. absence of goto is a major
annoyance. i'd like to see it in 4.x as well, but i realize that ain't gonna
happen officially.
paul
Goto is somewhat equivalent to 'case' combined with using 'continue' in loops.
More precisely, this 2 language constructions are the 'goto' implementation
with a different name so that Dijkstra does not get back from the grave to
punish us =D
It is true that goto is a little 'off-paradigm' in OOP and truly structured
languages, however, the point is this: sometimes continue and case produce
code that is not so clear and small at the same time as a little well used
goto. BUT goto allows non experienced or not well educated programmers to
begin writing horrible and totally unstructured code, and go further
developing bad programming habits... IMHO, would php be a more restrictive
language (strongly typed, or something alike) I would be totally and
unconditionally on for a goto addon. However, i see the bad habits and bad
code promotion as something that should be very carefully noted before
deciding whether to apply it or not.
I hope i have added some good points to help make the consideration deeper and
better =)
Regards
Leo
I wrote up a patch for implementing gotos in php scripts a couple months
ago as an exercise in working with the Zend engine. I put it aside
assuming noone would actually want it, but Wez and Ilia convinced me to
post it for consideration:Description:
http://pecl.orgPatch:
http://pecl.org/patches/opcode_goto_5.1.0.diffTalk amongst yourselves...
-Sara
--
Leonardo Pedretti
Axon Sistemas
Líder de Equipo Proyecto Basalto
Leonardo Pedretti wrote:
Goto is somewhat equivalent to 'case' combined with using 'continue' in loops.
More precisely, this 2 language constructions are the 'goto' implementation
with a different name so that Dijkstra does not get back from the grave to
punish us =D
also with exceptions there are also ways to "emulate" goto ...
might as well give people the real thing .. that is much more in the
spirit of php, where the aim is to make it very easily readable what you
are actually up to in your code.
regards,
Lukas
Goto is somewhat equivalent to 'case' combined with using 'continue' in loops.
More precisely, this 2 language constructions are the 'goto' implementation
with a different name so that Dijkstra does not get back from the grave to
punish us =D
It is true that goto is a little 'off-paradigm' in OOP and truly structured
languages, however, the point is this: sometimes continue and case produce
code that is not so clear and small at the same time as a little well used
goto. BUT goto allows non experienced or not well educated programmers to
begin writing horrible and totally unstructured code, and go further
developing bad programming habits... IMHO, would php be a more restrictive
language (strongly typed, or something alike) I would be totally and
unconditionally on for a goto addon. However, i see the bad habits and bad
code promotion as something that should be very carefully noted before
deciding whether to apply it or not.
I hope i have added some good points to help make the consideration deeper and
better =)
While it is true you can approximate the functionality of goto using
switch, or if/elseif/else constructs, these are inferior in efficiency.
Evaluation via switch or if/elseif/else system is O(n) just to get to
the desired block of code. Using goto, getting to the chosen code block
is O(1) (see note below). This is probably the most important reason why
many parsing implementations use goto.
Note
Goto jumping is O(1) if getting to the jump destination doesn't require
a hash lookup due to "wuring" of the destination at compile time. If a
hash lookup is required then it is probably something like O(lg n) which
is still superior in efficiency to O(n). Additionally, while it is true
that an O(lg n) lookup might be necessary at compile time to find the
pointer to the labeled code block, this is a one time event and has
little bearing on the efficiency overall when during runtime the goto
might be hit thousands or millions of times.
Cheers,
Rob.
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Note
Goto jumping is O(1) if getting to the jump destination doesn't require
a hash lookup due to "wuring" of the destination at compile time. If a
hash lookup is required then it is probably something like O(lg n) which
is still superior in efficiency to O(n). Additionally, while it is true
that an O(lg n) lookup might be necessary at compile time to find the
pointer to the labeled code block, this is a one time event and has
little bearing on the efficiency overall when during runtime the goto
might be hit thousands or millions of times.
this implementation of GOTO requires a hash lookup, however it could be
reworked to use the same backpatching as the ZEND_JMP ops used with
conditional statements. While doing that would speed execution time by
skipping the hash lookup, it'd slow compile time and remove the ability to
use complex expressions as goto targets (i.e. goto "foo$i"; ).
-Sara
Note
Goto jumping is O(1) if getting to the jump destination doesn't require
a hash lookup due to "wuring" of the destination at compile time. If a
hash lookup is required then it is probably something like O(lg n) which
is still superior in efficiency to O(n). Additionally, while it is true
that an O(lg n) lookup might be necessary at compile time to find the
pointer to the labeled code block, this is a one time event and has
little bearing on the efficiency overall when during runtime the goto
might be hit thousands or millions of times.this implementation of GOTO requires a hash lookup, however it could be
reworked to use the same backpatching as the ZEND_JMP ops used with
conditional statements. While doing that would speed execution time by
skipping the hash lookup, it'd slow compile time and remove the ability to
use complex expressions as goto targets (i.e. goto "foo$i"; ).
I'm not sure whether this is feasible or not, but perhaps a mix of
compile-time/runtime logic is possible. If the argument of the goto is a
literal then a compile-time jump hook is created, otherwise the argument
is evaluated at run-time. This would provide the best of both worlds,
but as I said I have no idea as to its feasibility.
Cheers,
Rob.
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
this implementation of GOTO requires a hash lookup, however it could be
reworked to use the same backpatching as the ZEND_JMP ops used with
conditional statements. While doing that would speed execution time by
skipping the hash lookup, it'd slow compile time and remove the ability to
use complex expressions as goto targets (i.e. goto "foo$i"; ).
I think that's a good thing actually ;-)
Derick
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine.
[...]
In the five or six year's I've been programming PHP, I haven't ever felt
the need to have "goto". Neither have I seen a newsgroup posting related
to it in the two years or so I followed the German PHP newsgroup,
de.comp.lang.php.
I don't think goto is really needed. People using other languages manage
to do without it, too.
So, -1.
- Timm
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine.
[...]In the five or six year's I've been programming PHP, I haven't ever felt
the need to have "goto". Neither have I seen a newsgroup posting related
to it in the two years or so I followed the German PHP newsgroup,
de.comp.lang.php.I don't think goto is really needed. People using other languages manage
to do without it, too.
C has it
C++ has it
VB has it
Lisp has "GO" which is pretty much the same
Perl
I'm sure many other too.
Just because people "manage" to do without it in some languages, doesn't
mean it isn't a useful feature.
Cheers,
Rob.
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Robert Cummings wrote:
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine.[...]
In the five or six year's I've been programming PHP, I haven't ever felt
the need to have "goto". Neither have I seen a newsgroup posting related
to it in the two years or so I followed the German PHP newsgroup,
de.comp.lang.php.I don't think goto is really needed. People using other languages manage
to do without it, too.C has it
Well, yes, C is very close the ASM, and ASM needs jmp-s.
C++ has it
Yes, C++ was designed to be as close to C as possible. I think
I read this in Straustrup's book. Thus C++ had to have goto.
VB has it
Yes, since it has it roots in Basic. Remember
10 Print "Hello"
20 Goto 10
Lisp has "GO" which is pretty much the same
No experience with Lisp :)
Perl
A language created by a hacker for hackers. I think Perl is quite
famous for the unmaintable code.
I'm sure many other too.
Just because people "manage" to do without it in some languages, doesn't
mean it isn't a useful feature.
Cheers,
Rob.
cheers,
andrey
Andrey,
Here are some more programming languages you may wish to discredit for their
goto support.
Fortran,
C#,
Cobol,
Ada
Ilia
Robert Cummings wrote:
I wrote up a patch for implementing gotos in php scripts a couple months
ago as an exercise in working with the Zend engine.[...]
In the five or six year's I've been programming PHP, I haven't ever felt
the need to have "goto". Neither have I seen a newsgroup posting related
to it in the two years or so I followed the German PHP newsgroup,
de.comp.lang.php.I don't think goto is really needed. People using other languages manage
to do without it, too.C has it
Well, yes, C is very close the ASM, and ASM needs jmp-s.
C++ has it
Yes, C++ was designed to be as close to C as possible. I think
I read this in Straustrup's book. Thus C++ had to have goto.VB has it
Yes, since it has it roots in Basic. Remember
10 Print "Hello"
20 Goto 10Lisp has "GO" which is pretty much the same
No experience with Lisp :)
Perl
A language created by a hacker for hackers. I think Perl is quite
famous for the unmaintable code.I'm sure many other too.
Just because people "manage" to do without it in some languages, doesn't
mean it isn't a useful feature.
Cheers,
Rob.cheers,
andrey
Ilia Alshanetsky wrote:
Andrey,
Here are some more programming languages you may wish to discredit for their
goto support.
This made me smile :)
Fortran,
this : http://cvs.php.net/co.php/pecl/stats/dcdflib.c?r=1.1
nice code has been written firstly in Fortran and then converted to C. When I want
to train my braincells I try to understand the code flow :)
C#,
Cobol,
Ada
I was trying to remember whether Ada has goto. I think Pascal also has. No idea why
the military guys needed goto in Ada :)
Ilia, my idea is that goto brings problems in most cases and I kind of saving my donkey
(and maybe the donkeys of other people) of some royal pain when we are pushed to support
badly written legacy code.
cheers,
andrey
Ilia, my idea is that goto brings problems in most cases and I kind of
saving my donkey (and maybe the donkeys of other people) of some royal pain
when we are pushed to support badly written legacy code.
Andrey,
Just ask and I'll show you oodles and oodles of PHP OO code that without a
doubt will leave you equally confused, perhaps even more so then the Fortran
-> C converted code you've decided to demonstrate. Despite the glaring abuse,
the OO support was further refined in PHP, to what purpose I wonder? Perhaps
it was to allow developers suprise and confound their friends and co-workers
at what a "simple" language can be made into? :-)
Ilia
Here are some more programming languages you may wish to discredit for
their
goto support.C#,
The C# goto is limited: "goto statements can transfer control within
blocks and out of blocks, but never into blocks." Does the PHP goto
implementation have this limitation?
http://www.jaggersoft.com/csharp_standard/15.4.htm
http://www.jaggersoft.com/csharp_standard/15.9.3.htm
Robert Cummings wrote:
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine.[...]
In the five or six year's I've been programming PHP, I haven't ever felt
the need to have "goto". Neither have I seen a newsgroup posting related
to it in the two years or so I followed the German PHP newsgroup,
de.comp.lang.php.I don't think goto is really needed. People using other languages manage
to do without it, too.C has it
Well, yes, C is very close the ASM, and ASM needs jmp-s.
And yet it isn't ASM.
C++ has it
Yes, C++ was designed to be as close to C as possible. I think
I read this in Straustrup's book. Thus C++ had to have goto.
Probably because C had a lot of good features. Isn't PHP also in many
ways modeled after C?
VB has it
Yes, since it has it roots in Basic. Remember
10 Print "Hello"
20 Goto 10
I think, and I doubt I'm alone, that there a world of difference between
the classical goto syntax where you "goto" the line number and what is
now considered good goto practice by declaring a label and jumping to
it. Not only that but goto in modern practice is limited to where it can
jump by it's current scope (not sure if scope is quite the right word,
but you know what I mean).
Lisp has "GO" which is pretty much the same
No experience with Lisp :)
I dislike LISP :)
Perl
A language created by a hacker for hackers. I think Perl is quite
famous for the unmaintable code.
Unmaintainable because of the ability to write cryptic code. There's
nothing cryptic about:
...code
goto cleanup:
...code
cleanup:
Cheers,
Rob.
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Robert Cummings wrote:
Unmaintainable because of the ability to write cryptic code. There's
nothing cryptic about:...code goto cleanup: ...code cleanup:
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...
Similar example in the PHP documentation.
I think I implemented once, just for the fun, a code similar
to the exceptions without the need of the goto and by
just using do{}while loop;
Cheers,
Rob.
thanks,
andrey
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...
Are you suggesting a hack is better than the real thing?
-Sara
Sara Golemon wrote:
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...Are you suggesting a hack is better than the real thing?
-Sara
The "hack" is working. The manual says :
" Advanced C users may be familiar with a different usage of the do..while loop,
to allow stopping execution in the middle of code blocks, by encapsulating them
with do..while (0), and using the break statement. The following code fragment
demonstrates this:" (a similar code follows)
" Don't worry if you don't understand this right away or at all. You can code scripts
and even powerful scripts without using this 'feature'. "
(the manual states that people can code powerful things without goto hack).
Sara, if you need to have the goto, you know how to implement it with do..while.
The average Joe may not need goto in some case but he will find that it simplifies
his job (but making code clumsy, something what he does not realize).
It is not because I don't like the power of goto, I would like not to be given in the
hands of the newbie.
andrey
Hello,
I think we should add an INI option:
php_newbie true|false
;)
--
Best regards,
Jason mailto:jason@ionzoft.com
Thursday, July 29, 2004, 8:54:34 PM, you wrote:
AH> Sara Golemon wrote:
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...Are you suggesting a hack is better than the real thing?
-Sara
AH> The "hack" is working. The manual says :
AH> " Advanced C users may be familiar with a different usage of the do..while loop,
AH> to allow stopping execution in the middle of code blocks, by encapsulating them
AH> with do..while (0), and using the break statement. The following code fragment
AH> demonstrates this:" (a similar code follows)
AH> " Don't worry if you don't understand this right away or at all. You can code scripts
AH> and even powerful scripts without using this 'feature'. "
AH> (the manual states that people can code powerful things without goto hack).
AH> Sara, if you need to have the goto, you know how to implement it with do..while.
AH> The average Joe may not need goto in some case but he will find that it simplifies
AH> his job (but making code clumsy, something what he does not realize).
AH> It is not because I don't like the power of goto, I would like not to be given in the
AH> hands of the newbie.
AH> andrey
----- Original Message -----
From: "Jason Garber" jason@ionzoft.com
To: internals@lists.php.net
Sent: Thursday, July 29, 2004 7:08 PM
Subject: Re: [PHP-DEV] GOTO operator
Hello,
I think we should add an INI option:
php_newbie true|false
i'm +1 on a -DI_KNOW_WHAT_IM_DOING <g>
paul
Jason Garber wrote:
Hello,
I think we should add an INI option:
php_newbie true|false
;)
better make it :
enable_goto = on|off
of course making the code non-portable :)
andrey
p.s. ok guys and ladies, i am going to sleep
a little bit (i need recharging). probably without me
the ML will be quite for a while :)
I think we should add an INI option:
php_newbie true|false
;)
better make it :
enable_goto = on|off
of course making the code non-portable :)
Ack! Gods no.... Andi is already winding up to rip me a new one for
prematurely committing the patch earlier today, don't push him over the edge
by suggesting das uberevil ini options, even in jest! ;)
-Sara
P.S. - Andi: Ya know I love ya more than my luggage... :)
.
.
.
Well, except for the carry-on.
At 04:55 PM 7/29/2004 -0700, Sara Golemon wrote:
Ack! Gods no.... Andi is already winding up to rip me a new one for
prematurely committing the patch earlier today, don't push him over the edge
by suggesting das uberevil ini options, even in jest! ;)-Sara
P.S. - Andi: Ya know I love ya more than my luggage... :)
Just got home from OSCON and about to go to sleep.
Sara: I have gotten over my initial heart attack from this morning so don't
worry about it :)
Let's for a second skip discussion of the patch itself, because although it
was an interesting exercise the patch is not production ready.
However, I think before talking about implementation, we need to decide if
goto is really good for PHP.
We talked about it quite a bit at OSCON, and I must say that I personally
think that adding goto to PHP will do more harm than good.
It is true that for some advanced programmers, goto can come in handy, but
the fact of the matter is that the PHP community has always taken a lot of
pride in providing a language which keeps away from these kind of shortcuts.
I think there are only two cases where goto is really interesting:
a) Error handling.
b) Auto-generating code or compiler compilers (Sterling mentioned these two).
I think that the cases where you need it for error handling in PHP code
aren't that great. Especially as the do..while(0) mechanism is much more
useful in PHP than in other languages due to the ability to do "break n;".
This ability in my opinion, is a good argument for why it's not as relevant
in PHP as in other languages. And unlike someone mentioned in this thread,
it is actually pretty fast and also takes care of all of the ugly stuff
such as memory leaks from opcodes (not that it couldn't be implemented for
goto but I'm just giving some more info and why it's a good thing).
I think that although slightly harder, code generators can probably also
use similar constructs and survive without goto. I wouldn't want to add
such a construct just for code generation. Sterling suggested calling the
language construct something like "goto_only_use_for_autogenerated_code"
(you get the point). His reasoning was that he doesn't really think it's
needed by the average developer but it would be useful for automated tools.
Not something I can completely disagree with but I think the downside
outweighs the benefits.
I think that one can always find examples of how goto is useful, but it's
hard to think ahead of time of how badly it will be abused. From my
experience, although not quite as clear, it'll definitely be used in
spaghetti code and will overall encourage bad coding practices, especially
for less advanced programmers than people on this list.
Yes, any programmer can shoot himself in the foot with other PHP features,
but we do have a responsibility to minimize that. One example is our
introduction of E_STRICT. We don't warn about enough things but we do try.
Why give our developers yet another way of shooting themselves in the foot?
Or should I say, blow off their leg? :)
Andi
Why give our developers yet another way of shooting themselves in the foot?
Or should I say, blow off their leg? :)
Seconded.
- Sascha
Andi Gutmans wrote:
[snip]
However, I think before talking about implementation, we need to decide
if goto is really good for PHP.
As I mentioned earlier, goto is one of the few features that I really
missed in the language for the past several years I've been using PHP.
We can debate until the end of time about it, but the fact is that it
can be a very useful tool.
I guess the question is if we should ban every feature that can be
abused by a novice developer? I guess there is no need to spell out my
answer to that :)
Edin
Edin Kadribasic wrote:
However, I think before talking about implementation, we need to
decide if goto is really good for PHP.As I mentioned earlier, goto is one of the few features that I really
missed in the language for the past several years I've been using PHP.
We can debate until the end of time about it, but the fact is that it
can be a very useful tool.
As long as it is not also a useful tool for hacking - GOTO -> backdoor!
Personally I see NO advantage to GOTO in a structured language, and even
if it is added I've learnt enough in 30 years to avoid it. Surely CASE
is much safer and naturally 'contained'?
--
Lester Caine
L.S.Caine Electronic Services
Edin Kadribasic wrote:
However, I think before talking about implementation, we need to
decide if goto is really good for PHP.As I mentioned earlier, goto is one of the few features that I really
missed in the language for the past several years I've been using PHP.
We can debate until the end of time about it, but the fact is that it
can be a very useful tool.As long as it is not also a useful tool for hacking - GOTO -> backdoor!
Personally I see NO advantage to GOTO in a structured language, and even
if it is added I've learnt enough in 30 years to avoid it. Surely CASE
is much safer and naturally 'contained'?
As I mentioned in an earlier post, regardless of what you can do with
case statements to emulate goto, why should I have to write O(n) code
because some newbie can shoot himself in the foot, or some zealot can't
get past the demonized goto construct of the ancient basic language.
There's absolutely nothing unclear about using goto to jump to a named
label within the owning function or method. It's definitely a lot
clearer and elegant then setting up a bunch of flags, or break N levels
out of while loops. Besides if you can make an argument for not having
goto, then why not make an argument for not having variable variables,
or variable function names. Come on, newbies can shoot themselves in the
foot with those too, and yet I haven't heard much in the way of
complaint.
Cheers,
Rob.
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Lester Caine wrote:
Personally I see NO advantage to GOTO in a structured language, and even
if it is added I've learnt enough in 30 years to avoid it. Surely CASE
is much safer and naturally 'contained'?
Two words: "State machine"
--
Hartmut Holzgraefe <hartmut@php.net
Hartmut Holzgraefe wrote:
Personally I see NO advantage to GOTO in a structured language, and
even if it is added I've learnt enough in 30 years to avoid it. Surely
CASE is much safer and naturally 'contained'?Two words: "State machine"
So what - the database tells me what to run next for each user - based
on their responses - I don't need a GOTO ;)
--
Lester Caine
L.S.Caine Electronic Services
At 04:55 PM 7/29/2004 -0700, Sara Golemon wrote:
I think there are only two cases where goto is really interesting:
a) Error handling.
b) Auto-generating code or compiler compilers (Sterling mentioned these
two).
c) Anywhere recursive functions are being used.
d) small loop inlining
There are other applications as you had yourself mentioned, ultimately goto is
a construct that can be used for both good & bad code. But that can be said
for many of PHP's features that no one even suggests removing.
Yes, any programmer can shoot himself in the foot with other PHP features,
but we do have a responsibility to minimize that. One example is our
introduction of E_STRICT. We don't warn about enough things but we do try.
Why give our developers yet another way of shooting themselves in the foot?
Or should I say, blow off their leg? :)
If we really want to protect the user from themselves perhaps we should limit
the user to addition and subtraction between the values of 1 and 100. That is
ultimately what would become a language designed for the lowest common
denominator.
You can already do some pretty wild things without triggering any notices with
perfectly valid and even working code. But that code will be 100% unreadable
let alone maintainable adding gotos will unlikely to change that in any
significant way.
While without a doubt some people will abuse GOTO there are plenty of
developers who'd put it to good use in their application, perhaps utilizing
it ways we haven't even considered yet. If anything this discussion had
proved that there is much support/need for GOTOs in both PHP developer and
user communities.
Ilia
The main argument against providing the 'goto' statement seems to be to
protect users from themselves.
So, let's analyze the situation. In the languages which provide the
'goto' statement, is this functionality widely abused?
I have used a number of Open Source projects in several different
languages and can attest to rarely even seeing a 'goto' statement.
Based on this I personally don't believe it will be so abused, but
perhaps I haven't seen enough code..
Dan Cox
Hello,
After thinking about it for a bit, I'm convinced. If goto can be
implemented so that it is fast, and does not adversely affect other
parts of PHP, by all means, do it.
Andrey, you've been very clear why you would not use it, but why do
you want me not to use it? I can think of quite a few times when it
would have made my code much cleaner.
As far as shooting yourself in the foot, how about:
mysql_query("SELECT x,y,z FROM t WHERE id=" . $_GET['id']);
or
include($_GET['header_file']);
or
shell_exec('somecommand ' . $_POST['param']);
There are PLENTY of way's to shoot yourself in the foot with any
language. If joe shoots himself in his foot, does that mean that
I should not be allowed to shoot at all?
+1
--
Best regards,
Jason mailto:jason@ionzoft.com
Andrey Hristov wrote:
Robert Cummings wrote:
Unmaintainable because of the ability to write cryptic code. There's
nothing cryptic about:...code goto cleanup: ...code cleanup:
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...
This works for one level, but imagine:
... code ... (which exits with goto_out)
if (!alloc x)
goto out;
... code ... (which exits with goto_outfreex)
if (!alloc y)
goto out_freex;
... code ... (which exits with goto_outfreey)
if (!alloc z)
goto out_freey;
... code ...
free z;
out_freey:
free y;
out_freex:
free x;
out:
print bye;
For this you'll need 3 nested do{}while(); loops and your indention is
so far to the right, that you can barely write more than two more words
on a line.
This really looks a lot cleaner with goto.
Jan
Jan Dittmer wrote:
Andrey Hristov wrote:
Robert Cummings wrote:
Unmaintainable because of the ability to write cryptic code. There's
nothing cryptic about:...code goto cleanup: ...code cleanup:
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...This works for one level, but imagine:
... code ... (which exits with goto_out)
if (!alloc x)
goto out;... code ... (which exits with goto_outfreex)
if (!alloc y)
goto out_freex;... code ... (which exits with goto_outfreey)
if (!alloc z)
goto out_freey;... code ...
free z;
out_freey:
free y;
out_freex:
free x;
out:
print bye;For this you'll need 3 nested do{}while(); loops and your indention is
so far to the right, that you can barely write more than two more words
on a line.
This really looks a lot cleaner with goto.
I just woke up but I think this can be solved with one do..while and using
bitfield for example. so when you break, just check the bitfield what to
clean up.
$clean = 0;
do {
$res = some_op();
if (!$res && $clean|=CLEAN_TYPE1) break;
$res = some_op2();
if (!$res && $clean|=CLEAN_TYPE1) break;
$res = some_op3();
if (!$res && $clean|=CLEAN_TYPE2) break;
} while (0);
if ($res & CLEAN_TYPE1) {
//do clean type 1
}
if ($clean & CLEAN_TYPE2) {
// do clean type 2
}
But I see that in your case simple variable and then having switch() after
the do..while will be enough, just fall-through will be used.
regards,
andrey
p.s.
thanks for the nice example :) good exercise for the brain early in the morning :)
"Andrey Hristov" php@hristov.com wrote in message
news:410A140A.3080008@hristov.com...
Jan Dittmer wrote:
Andrey Hristov wrote:
Robert Cummings wrote:
Unmaintainable because of the ability to write cryptic code. There's
nothing cryptic about:...code goto cleanup: ...code cleanup:
do {
.....code...
if (something) break;
...code....
} while (0);
...cleanup code...This works for one level, but imagine:
... code ... (which exits with goto_out)
if (!alloc x)
goto out;... code ... (which exits with goto_outfreex)
if (!alloc y)
goto out_freex;... code ... (which exits with goto_outfreey)
if (!alloc z)
goto out_freey;... code ...
free z;
out_freey:
free y;
out_freex:
free x;
out:
print bye;For this you'll need 3 nested do{}while(); loops and your indention is
so far to the right, that you can barely write more than two more words
on a line.
This really looks a lot cleaner with goto.
The way I would do it is to nest it in multiple layers of try/catch
try
{
try
{
//code
}catch(goto_outfreez)
{
//process
//rethrow exception
}
}
catch (goto_outfreey)
{
//process
//rethrow exception
}
This would look better if I could write this code in an IDE w/
auto-indenting instead of Outlook Express.
In terms of visual appearance, you may be right. I'm used to Java now, so I
would currently be more accustomed to seeing multiple indentation layers
(which is why I'm getting a widescreen notebook soon).
Robert Cummings wrote:
C has it
C++ has it
VB has it
Lisp has "GO" which is pretty much the same
PerlI'm sure many other too.
Even PASCAL, the mother of "structured code" languages, has it!
--
Hartmut Holzgraefe <hartmut@php.net
In the five or six year's I've been programming PHP, I haven't ever felt
the need to have "goto". Neither have I seen a newsgroup posting related
to it in the two years or so I followed the German PHP newsgroup,
de.comp.lang.php.
I must admit that an average guestbook script does not need gotos and probably
would work best without them. That said PHP now a days is used for a whole
lot of different and exciting things, which in many instances can benefit
from "goto" availability.
Ilia
Personally I would never use it myself, as I know of better ways around it
which make more sense to me. But on the other hand if it would help others
then more power to yah. I think the argument of user's abusing it is bogus,
as clearly mentioned in this thread. There isn't a WTF factor, as almost
everyone knows what goto does. So frankly it boils down to this.
a.) If it can be added without affecting anything I do then great, do it.
b.) If your in the camp who is against using it (like me) then don't, but
don't tell others what they can and can't use.
c.) Newbies will be newbies no matter how much you hand hold them, so just let
them be newbies and hope they grow out of it sooner than later.
Just my 2c...
-Jeremy
I wrote up a patch for implementing gotos in php scripts a couple months
ago as an exercise in working with the Zend engine. I put it aside
assuming noone would actually want it, but Wez and Ilia convinced me to
post it for consideration:Description:
http://pecl.orgPatch:
http://pecl.org/patches/opcode_goto_5.1.0.diffTalk amongst yourselves...
-Sara
I wrote up a patch for implementing gotos in php scripts a couple months ago
as an exercise in working with the Zend engine. I put it aside assuming
noone would actually want it, but Wez and Ilia convinced me to post it for
consideration:Description:
http://pecl.org
I think we should make it allow constant label names only, doing it
dynamically is just too confusing to read later on.
Derick