GOTO operator

php.internals

Sara Golemon

22 years ago
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

Robert Cummings

22 years ago
On Wed, 2004-07-28 at 22:12, Sara Golemon 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. 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...
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. | `------------------------------------------------------------'

Edin Kadribasic

22 years ago
On Thursday 29 July 2004 04:12, Sara Golemon 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. 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

Wez Furlong

22 years ago
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. On Wed, 28 Jul 2004 19:12:40 -0700, Sara Golemon <pollita@php.net> wrote:

Sara Golemon

22 years ago
> 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

Ilia A.

22 years ago
Goto is an extremely useful for parsers and makes life much easier when dealing with complex error handling situations. +1 Ilia On July 28, 2004 10:12 pm, Sara Golemon wrote:

Georg Richter

22 years ago
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

Alex Pagnoni

22 years ago
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

Jacques Marneweck

22 years ago
+1 On Wed, 28 Jul 2004 22:55:53 -0400, Ilia Alshanetsky <ilia@prohost.org> wrote:
> Goto is an extremely useful for parsers and makes life much easier when > dealing with complex error handling situations. > > +1 > > Ilia > > > > On July 28, 2004 10:12 pm, Sara Golemon 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. 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- Jacques Marneweck http://www.powertrip.co.za/blog/

Stefan Esser

22 years ago
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

Paul G

22 years ago
----- 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

Leonardo Pedretti

22 years ago
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 On Wednesday 28 July 2004 23:12, Sara Golemon 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. 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
-- Leonardo Pedretti Axon Sistemas Líder de Equipo Proyecto Basalto

Ilia A.

22 years ago
PHP is a not a type strict language, far from it and it is unlikely it'll ever be such. It is also a not pure OOP language and I very much doubt it'll ever be one. While GOTO can be abused, so can any other language feature, such as OOP, or the ability to include remote files. If we add this feature certain warnings should made about it using it (as with almost any feature), but I see no reason to cripple advanced users simply other users may find fun and usual ways to abuse this useful functionality. Anyone who has ever written a parser will tell you GOTO is absolutely essential unless you want to go into recursive functions etc... which are way slower. GOTO also provides a fast an safe alternative to many solution where so far the only viable option (for most people) have been a recursive functions and those tend to smash the stack once in a while. Ilia On July 29, 2004 10:17 am, Leonardo Pedretti wrote:

Andrey Hristov

22 years ago
Ilia Alshanetsky wrote:
> PHP is a not a type strict language, far from it and it is unlikely it'll ever > be such. It is also a not pure OOP language and I very much doubt it'll ever > be one. > While GOTO can be abused, so can any other language feature, such as OOP, or > the ability to include remote files. If we add this feature certain warnings > should made about it using it (as with almost any feature), but I see no > reason to cripple advanced users simply other users may find fun and usual > ways to abuse this useful functionality. Anyone who has ever written a parser > will tell you GOTO is absolutely essential unless you want to go into > recursive functions etc... which are way slower. GOTO also provides a fast an > safe alternative to many solution where so far the only viable option (for > most people) have been a recursive functions and those tend to smash the > stack once in a while. >
Is the average Joe going to write parsers in the everydays work? Probably not. But give him the power of goto and (s)he is going to shoot him/her in the legs, in the heart, in the head. And even not only himself because (s)he will create a legacy code which someone else has to understand and fix. We have extract() and we say in the docs it is not good to use it to populate variables but people hack and workaround register_globals set to off by just using this function. IMO PHP has enough power even without "goto". Left aside what Dijkstra has written. goto code tends to become spaghetti one. Sometimes I miss it when write PHP scripts (for example jumping between 2 clauses in a switch, something which is used in var_dump() C implementation) but then I reconsider that it is better this way. Looks like I am -1 if that counts :) thanks, andrey

Ilia A.

22 years ago
On July 29, 2004 08:00 pm, Andrey Hristov wrote:
> Is the average Joe going to write parsers in the everydays work? Probably > not. But give him the power of goto and (s)he is going to shoot him/her in > the legs, in the heart, in the head. And even not only himself because > (s)he will create a legacy code which someone else has to understand and > fix. We have extract() and we say in the docs it is not good to use it to > populate variables but people hack and workaround register_globals set to > off by just using this function. IMO PHP has enough power even without > "goto". Left aside what Dijkstra has written. goto code tends to become > spaghetti one. Sometimes I miss it when write PHP scripts (for example > jumping between 2 clauses in a switch, something which is used in > var_dump() C implementation) but then I reconsider that it is better this > way.
Parsers are just one place where GOTOs show their merit. GOTOs can be immensely useful error handling mechanism that can save having to make dozens of functions just to avoid code duplication. As I had mentioned earlier GOTO can be used to eliminate stack smashes caused by recursive functions that are the simplest solution (according to average Joe) to many problems. IMHO just saying something can be abused does not seem like a good reason, because that can applied to anything. Exceptions can be abused, OO can be abused, xml can be abused, etc... Ilia

Sara Golemon

22 years ago
> Is the average Joe going to write parsers in the everydays work? Probably
not.
> But give him the power of goto and (s)he is going to shoot him/her in the
legs,
> in the heart, in the head. And even not only himself because (s)he will
create a
> legacy code which someone else has to understand and fix. >
function foo() { foo(); } for($i = 0; $i < 10; $i--); `php -f {$_SERVER['PHP_SELF']}`; while (!($fp = fopen('/does/not/exist', 'r'))); All oversimplistic examples obviously, but the concepts aren't unfamiliar to those of us that actually volunteer in the trenches on usenet, irc, forums, etc... To quote Wez: "GOTO doesn't kill code, bad programmers do."
> We have extract() > and we say in the docs it is not good to use it to populate variables but
people
> hack and workaround register_globals set to off by just using this
function.
>
Taking away their tools will not make them code more intelligently, it'll send them off to another language where they CAN continue making the same mistakes. The way to breed better programmers is to point out their mistakes and suggest how they can correct them. But not every implementation of a particular concept is a mistake, if it were we'd have only one CMS, only one gallery script, only one Blog, and come to that.... only one language.
> IMO PHP has enough power even without "goto". Left aside what Dijkstra has > written. goto code tends to become spaghetti one. >
I could just as easily state that nested code with lots of OOP does the same thing. I'll say it agin: "GOTO doesn't kill code, bad programmers do."
> Sometimes I miss it when > write PHP scripts (for example jumping between 2 clauses in a switch,
something
> which is used in var_dump() C implementation) but then I reconsider that
it is better
> this way. >
Often it is better. And sometimes it's not. Funny how generalizations work.
> Looks like I am -1 if that counts :) >
Damn skippy it does. Everyone's oppinion counts. Whether the dicision is made to add it or leave it out, the voices of this community will have made an impact on that decision. -Sara

Paul G

22 years ago
----- Original Message ----- From: "Andrey Hristov" <php@hristov.com> To: <ilia@prohost.org> Cc: <internals@lists.php.net> Sent: Thursday, July 29, 2004 8:00 PM Subject: Re: [PHP-DEV] GOTO operator --- snip ---
> Is the average Joe going to write parsers in the everydays work? Probably
not. how about: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); $res=do_stuff(); if(!$res) goto err_out; $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) goto err_out; $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) goto err_out; return true; err_out: free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); return false; } here the do_stuff()s would be trivial inline code that makes no sense to break out, each being a few slocs. everything looks neat and it is perfectly clear what is going on. with no goto: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); $res=do_stuff(); if(!$res) { free_resource($a); free_resource($b); return false; } $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) { free_resouce($a); free_resource($b); free_resource($c); return false; } $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) { free_resouce($a); free_resource($b); free_resource($c); free_resource($d); return false; } return true; } .. now imagine this isn't pseudocode, but actual code. you're doing a bunch of stuff and the repetition becomes extremely unmanagable, especially if you are doing miantenance later. ie, say you allocate another resource at the beginning - add a free_resource() in one place only with the goto example, in N places without. before you discount the resource allocation stuff (in C this would be primarily malloc()s), there is quite enough stuff that you can 'allocate' in real code that isn't going to get gc'ed. and yes, i've been missing goto dearly when doing real development. right now, i'm emulating it by implementing allocation functions such that they keep a list (or hashtable rather) of resources belonging to each function and i can release them all in one line of code, but i'm still replicating that line of code everywhere and, quite frankly, it's a kludge. i agree with ilia - dont' castrate the language in a misguided effort to protect the clueless. abuse of goto is best prevented by education on its proper uses (few very specific cases). paul

Andrey Hristov

22 years ago
Paul G wrote:
> ----- Original Message ----- > From: "Andrey Hristov" <php@hristov.com> > To: <ilia@prohost.org> > Cc: <internals@lists.php.net> > Sent: Thursday, July 29, 2004 8:00 PM > Subject: Re: [PHP-DEV] GOTO operator > > > --- snip --- > > >>Is the average Joe going to write parsers in the everydays work? Probably > > not. > > how about: > > function pseudocode() > { > $a=allocate_resource_z(); > $b=allocate_resource_y(); > > $res=do_stuff(); > if(!$res) > goto err_out; > > $c=allocate_resource_x(); > $res=do_more_stuff(); > if(!$res) > goto err_out; > > $d=allocate_resource_foo(); > $res=do_even_more_stuff(); > if(!$res) > goto err_out; > > return true; > > err_out: > free_resouce($a); > free_resouce($b); > if(isset($c)) free_resouce($c); > if(isset($d)) free_resouce($c); > > return false; > }
no goto : other implementation function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); do { $res=do_stuff(); if(!$res) break; $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) break; $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) break; return true; } while (0); free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); return false; } andrey

Edin Kadribasic

22 years ago
On Friday 30 July 2004 00:43, Paul G wrote: [snip] This is exactly the kind of code that makes me miss goto so much for error handling. Edin

Paul G

22 years ago
----- Original Message ----- From: "Edin Kadribasic" <edink@emini.dk> To: <internals@lists.php.net> Cc: "Paul G" <paul@rusko.us> Sent: Thursday, July 29, 2004 6:55 PM Subject: Re: [PHP-DEV] GOTO operator
> On Friday 30 July 2004 00:43, Paul G wrote: > [snip] > > This is exactly the kind of code that makes me miss goto so much for error > handling.
ack. in a previous life, i was doing work on a filesystem implementaion (uggh). if i had no goto, i'd have hung myself (not a pretty sight, the poor tree would've had its work cut out for it). what i'm doing in php now is equally hairy. paul

Derick Rethans

22 years ago
On Fri, 30 Jul 2004, Edin Kadribasic wrote:
> On Friday 30 July 2004 00:43, Paul G wrote: > [snip] > > This is exactly the kind of code that makes me miss goto so much for error > handling.
I agree with that, +1 on goto from me, but still... only constant labels please! Derick

Shaun Thomas

22 years ago
Paul G wrote:
> function pseudocode() > { > $a=allocate_resource_z(); > $b=allocate_resource_y(); > > $res=do_stuff(); > if(!$res) > goto err_out; > > $c=allocate_resource_x(); > $res=do_more_stuff(); > if(!$res) > goto err_out; > > $d=allocate_resource_foo(); > $res=do_even_more_stuff(); > if(!$res) > goto err_out; > > return true; > > err_out: > free_resouce($a); > free_resouce($b); > if(isset($c)) free_resouce($c); > if(isset($d)) free_resouce($c); > > return false; > }
While this is valid, it's not really a good example of pseudocode that requires a goto to be efficient. You could do the same thing with try/catch/throw: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); try { $res=do_stuff(); if(!$res) throw SOME_ERROR; $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) throw SOME_ERROR; $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) throw SOME_ERROR; return true; } catch SOME_ERROR { free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); return false; } } This is also one of the reasons languages like Ada have named code blocks for exceptions. Here's some ada-like pseudo-code: BEGIN a := allocate_resource_z(); b := allocate_resource_y(); res := do_stuff(); if (!res) raise some_exception; c := allocate_resource_x(); res := =do_more_stuff(); if (!res) raise some_exception; d := allocate_resource_foo(); res := do_even_more_stuff(); if(!res) raise unknown; return TRUE; EXCEPTION free_resouce(a); free_resouce(b); if (c) free_resouce(c); if (d) free_resouce(c); return FALSE; END The case that Ilia and the other main developers is not for cases like this. If you look through the Linux kernel, you can see very good examples of goto usage that is not related to this kind of error handling. It's mainly to jump around inside parsing code while maintaining a stack, so the same chunk of code can continuously handle the same source of input without hundreds of if statements and indented blocks.
-- Shaun M. Thomas INN Database Administrator Phone: (309) 743-0812 Fax : (309) 743-0830 Email: sthomas@townnews.com Web : www.townnews.com

Jeff Moore

22 years ago
On Jul 30, 2004, at 10:35 AM, Shaun Thomas wrote:
> Paul G wrote: > >> function pseudocode() >> { >> $a=allocate_resource_z(); >> $b=allocate_resource_y(); >> $res=do_stuff(); >> if(!$res) >> goto err_out; >> $c=allocate_resource_x(); >> $res=do_more_stuff(); >> if(!$res) >> goto err_out; >> $d=allocate_resource_foo(); >> $res=do_even_more_stuff(); >> if(!$res) >> goto err_out; >> return true; >> err_out: >> free_resouce($a); >> free_resouce($b); >> if(isset($c)) free_resouce($c); >> if(isset($d)) free_resouce($c); >> return false; >> } > > While this is valid, it's not really a good example of pseudocode that > requires a goto to be efficient. You could do the same thing with > try/catch/throw: > > function pseudocode() > { > $a=allocate_resource_z(); > $b=allocate_resource_y(); > > try { > $res=do_stuff(); > if(!$res) > throw SOME_ERROR; > > $c=allocate_resource_x(); > $res=do_more_stuff(); > if(!$res) > throw SOME_ERROR; > > $d=allocate_resource_foo(); > $res=do_even_more_stuff(); > if(!$res) > throw SOME_ERROR; > > return true; > } > > catch SOME_ERROR { > free_resouce($a); > free_resouce($b); > if(isset($c)) free_resouce($c); > if(isset($d)) free_resouce($c); > > return false; > } > }
I would prefer to write the original code as follows: function pseudocode() { try { $a = allocate_resource_z(); $b = allocate_resource_y(); $res = do_stuff(); $c = allocate_resource_x(); $res = do_more_stuff(); $d = allocate_resource_foo(); $res = do_even_more_stuff(); } catch ( Exception $e ) { free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c);        throw ($e); } } Where did the if statements go? do_stuff(), do_more_stuff(), and do_even_more_stuff() should throw exceptions rather than return boolean error indicators. (Following the principle of raising the error as soon as it can be detected.) This implementation of pseudocode() also re-throws the exception, rather than use a boolean error return value. One major benefit of exceptions is to eliminate conditional statements as error codes "bubble up." goto does not help with this.

Edin Kadribasic

22 years ago
Jeff Moore wrote:
> Where did the if statements go? do_stuff(), do_more_stuff(), and > do_even_more_stuff() should throw exceptions rather than return boolean > error indicators.
Now imagine do_stuff() and friends were native PHP functions ;) Edin

David Kingma

22 years ago
>> Where did the if statements go? do_stuff(), do_more_stuff(), and >> do_even_more_stuff() should throw exceptions rather than return >> boolean error indicators. > >Now imagine do_stuff() and friends were native PHP functions ;)
Good point, but should we fix this with a goto operator or get to the source of the problem (that would break BC wouldn't it?)?

Edin Kadribasic

22 years ago
David Kingma wrote:
>>>Where did the if statements go? do_stuff(), do_more_stuff(), and >>>do_even_more_stuff() should throw exceptions rather than return >>>boolean error indicators. >> >>Now imagine do_stuff() and friends were native PHP functions ;) > > > Good point, but should we fix this with a goto operator or get to the source > of the problem (that would break BC wouldn't it?)? >
Exactly. The BC consideration would probably mean that this is never going to be implemented. Edin

Jeff Moore

22 years ago
On Jul 30, 2004, at 4:33 PM, Edin Kadribasic wrote:
> Jeff Moore wrote: > >> Where did the if statements go? do_stuff(), do_more_stuff(), and >> do_even_more_stuff() should throw exceptions rather than return >> boolean error indicators. > > Now imagine do_stuff() and friends were native PHP functions ;)
You might also have installed a standard error handler to raise some kinds of php errors as exceptions. In the worst case, you would have to add the if ... throws and you would be no worse off at the lowest level. However, the caller of the enclosing pseudocode() function would not have to check for a boolean error code and so try/catch is still a net gain.

Derick Rethans

22 years ago
On Fri, 30 Jul 2004, Jeff Moore wrote:
> > On Jul 30, 2004, at 4:33 PM, Edin Kadribasic wrote: > > > Jeff Moore wrote: > > > >> Where did the if statements go? do_stuff(), do_more_stuff(), and > >> do_even_more_stuff() should throw exceptions rather than return > >> boolean error indicators. > > > > Now imagine do_stuff() and friends were native PHP functions ;) > > You might also have installed a standard error handler to raise some > kinds of php errors as exceptions.
Exceptions are an OO thing, and it makes NO sense to use them in procedural code. Goto is a good thing here. Derick

Zeev Suraski

22 years ago
At 15:45 31/07/2004, Derick Rethans wrote:
>Exceptions are an OO thing, and it makes NO sense to use them in >procedural code. Goto is a good thing here.
Can you explain why it makes no sense to use them in procedural code? It makes perfect sense for me, and they render 100.0% of the examples shown on internals@ redundant... Zeev

Shaun Thomas

22 years ago
Jeff Moore wrote:
> function pseudocode() { > try { > $a = allocate_resource_z(); > $b = allocate_resource_y(); > $res = do_stuff(); > $c = allocate_resource_x(); > $res = do_more_stuff(); > $d = allocate_resource_foo(); > $res = do_even_more_stuff(); > } catch ( Exception $e ) { > free_resouce($a); > free_resouce($b); > if(isset($c)) free_resouce($c); > if(isset($d)) free_resouce($c); > throw ($e); > } > } > > Where did the if statements go? do_stuff(), do_more_stuff(), and > do_even_more_stuff() should throw exceptions rather than return boolean > error indicators.
True, which is really just a more revised version of the point that's been being passed around in one form or another. I was assuming the functions called didn't necessarily throw errors, like a PHP internal or similar, where you'd want to check the return code - but for an application coded around try/catch/throw, this would work perfectly. Personally, I'm used to the PEAR_Error, and PEAR::isError() method of error handling, so having the luxury of try/catch/throw in PHP 5 is a major improvement. But I guess the point is that having goto isn't really essential, as the original example tried to imply. But Ilia and Rasmus are also correct in that it wouldn't really hurt anything to add goto functionality, either. Most would ignore it, and it can only scope locally, so there's little chance of spaghetti. Sure, it's gross in general, but PHP isn't Python: enforcing coding style isn't PHP's thing. And as others have pointed out, we can all cite code that looks nasty, regardless of the presence of goto. For anyone who's ever seen Python code that *only* follows the indentation requirement, it does little to improve overall quality of the end product. Bad programmers will always find ways around language constructs, intentionally or otherwise. I'm just waiting for a language that imposes Javadoc style commenting in a 40% or greater ratio of comments to code, consistent indentation, brace style, and so on, just to see how it gets circumvented. Which is why I find it amusing PHP enforces camel-caps for class method names; that simply encourages bad programmers to use all lower case to avoid the issue entirely.
-- Shaun M. Thomas INN Database Administrator Phone: (309) 743-0812 Fax : (309) 743-0830 Email: sthomas@townnews.com Web : www.townnews.com

Lukas Smith

22 years ago
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

Robert Cummings

22 years ago
On Thu, 2004-07-29 at 10:17, 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 > 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. | `------------------------------------------------------------'

Sara Golemon

22 years ago
> 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

Robert Cummings

22 years ago
On Thu, 2004-07-29 at 11:04, Sara Golemon wrote:
> > 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. | `------------------------------------------------------------'

Derick Rethans

22 years ago
On Thu, 29 Jul 2004, Sara Golemon wrote:
> *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

Timm Friebe

22 years ago
On Thu, 2004-07-29 at 04:12, Sara Golemon 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. So, -1. - Timm

Robert Cummings

22 years ago
On Thu, 2004-07-29 at 17:25, Timm Friebe wrote:
> On Thu, 2004-07-29 at 04:12, Sara Golemon 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 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. | `------------------------------------------------------------'

Andrey Hristov

22 years ago
Robert Cummings wrote:
> On Thu, 2004-07-29 at 17:25, Timm Friebe wrote: > >>On Thu, 2004-07-29 at 04:12, Sara Golemon 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

Ilia A.

22 years ago
Andrey, Here are some more programming languages you may wish to discredit for their goto support. Fortran, C#, Cobol, Ada Ilia On July 29, 2004 08:10 pm, Andrey Hristov wrote:

Andrey Hristov

22 years ago
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 A.

22 years ago
On July 29, 2004 08:32 pm, Andrey Hristov wrote:
> 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

Jeff Moore

22 years ago
On Jul 29, 2004, at 6:30 PM, Ilia Alshanetsky wrote:
> 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

Andi Gutmans

22 years ago
At 02:38 PM 7/30/2004 -0400, Jeff Moore wrote:
>On Jul 29, 2004, at 6:30 PM, Ilia Alshanetsky wrote: > >>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
No it doesn't. As I mentioned Sara's implementation is extremely flawed. So yes there is a technical issue here beside a semantic issue. And the C# limitation might very well apply in PHP too. Andi

Sara Golemon

22 years ago
> >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? > > > No it doesn't. As I mentioned Sara's implementation is extremely flawed.
So
> yes there is a technical issue here beside a semantic issue. And the C# > limitation might very well apply in PHP too. >
Flag on the play.... Yes it *DOES* have this limiter as I've stated at least 4 times on this list and in the patch description itself. I can't tell you how encouraging it is to hear counter-arguments from people who havn't taken the time to explore the topic at hand. I would love to hear what these flaws are so that I can fix them. Regardless of whether or not GOTO is added to PHP I'd like to improve my ability to maintain and work on the language efficiently. -Sara

Sara Golemon

22 years ago
"Sara Golemon" <pollita@php.net> wrote in message news:20040730185734.76549.qmail@pb1.pair.com...
> > >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? > > > > > No it doesn't. As I mentioned Sara's implementation is extremely flawed. > So > > yes there is a technical issue here beside a semantic issue. And the C# > > limitation might very well apply in PHP too. > > >
To clarify my earlier (energized) post. There is jumping into blocks, I was referring to a different layer of scope. My bad. But I'm still curious what flaws are seen. This goto implementation was tested with many different combinations of jumping into and out of control blocks (including try/catch) with expected results every time. -Sara

Andi Gutmans

22 years ago
At 11:56 AM 7/30/2004 -0700, Sara Golemon wrote:
> > >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? > > > > > No it doesn't. As I mentioned Sara's implementation is extremely flawed. >So > > yes there is a technical issue here beside a semantic issue. And the C# > > limitation might very well apply in PHP too. > > >Flag on the play.... > >Yes it *DOES* have this limiter as I've stated at least 4 times on this list >and in the patch description itself. I can't tell you how encouraging it >is to hear counter-arguments from people who havn't taken the time to >explore the topic at hand. > >I would love to hear what these flaws are so that I can fix them. >Regardless of whether or not GOTO is added to PHP I'd like to improve my >ability to maintain and work on the language efficiently.
Hi Sara, I thought you were aware of the problems (that's what I understood from you). I guess I got the wrong idea and in no way meant to insult your work. A few problems: a) Performance wise the right thing to do is to use static labels and pre-compute them during compile-time (I remembered you were aware of that). b) We therefore should not require an additional opcode for goto. c) I don't think you are creating the necessary switch_free's and other frees when jumping out of a scope unexpectedly. d) Due to (c) it would make it pretty much impossible to jump into code blocks (i.e. the C# example). Again, I in know way meant to offend you, I just got the impression you were aware of some of these problems and just did it for fun. Andi

Sara Golemon

22 years ago
> a) Performance wise the right thing to do is to use static labels and > pre-compute them during compile-time (I remembered you were aware of
that).
> b) We therefore should not require an additional opcode for goto. >
I did consider that, but the idea of computed targets (goto "foo$bar";) souded sexy enough to go with. Someone suggested mixing pre-computed static gotos (using ZEND_JMP) and runtime dynamic gotos (using ZEND_GOTO) to get the best of speed and flexibility.
> c) I don't think you are creating the necessary switch_free's and other > frees when jumping out of a scope unexpectedly. >
Entirely possible. The tests I've run don't complain but that doesn't mean something bad isn't happening.
> d) Due to (c) it would make it pretty much impossible to jump into code > blocks (i.e. the C# example). >
Again, for some reason it "works" in my simple test cases, but it sounds like I need to do some more digging and find out what's not being done and where it'll break in more complex code.
> Again, I in no way meant to offend you, I just got the impression you > were aware of some of these problems and just did it for fun. >
Assumptions are bad, and I've made my own fair number, but if I thought there were significant problems I wouldn't have let anyone see the code in the first place. :) -Sara

Andi Gutmans

22 years ago
At 12:13 PM 7/30/2004 -0700, Sara Golemon wrote:
> > a) Performance wise the right thing to do is to use static labels and > > pre-compute them during compile-time (I remembered you were aware of >that). > > b) We therefore should not require an additional opcode for goto. > > >I did consider that, but the idea of computed targets (goto "foo$bar";) >souded sexy enough to go with. Someone suggested mixing pre-computed static >gotos (using ZEND_JMP) and runtime dynamic gotos (using ZEND_GOTO) to get >the best of speed and flexibility.
I don't think we should be using computed targets. It'd be more of a nightmare than sexy. I prefer doing as much at compile-time as possible and I don't think that allowing indirect goto's would lead to anything than chaos. Most arguments in favor of goto were for circumstances where this would not be required. (And yes, even if we pre-compute what we can and add the hash and opcode for the instances we can't pre-compute I think it's a very bad idea). I feel about 1000 times stronger about that than goto :)
> > c) I don't think you are creating the necessary switch_free's and other > > frees when jumping out of a scope unexpectedly. > > >Entirely possible. The tests I've run don't complain but that doesn't mean >something bad isn't happening.
Leaks but it's not always easy to reproduce those.
> > d) Due to (c) it would make it pretty much impossible to jump into code > > blocks (i.e. the C# example). > > >Again, for some reason it "works" in my simple test cases, but it sounds >like I need to do some more digging and find out what's not being done and >where it'll break in more complex code.
You will have situations where values accessed by the engine are not initialized and therefore most probably crash. There is no magic bullet solution and I assume C# has this limitation for similar reasons (Although I have no idea).
> > Again, I in no way meant to offend you, I just got the impression you > > were aware of some of these problems and just did it for fun. > > >Assumptions are bad, and I've made my own fair number, but if I thought >there were significant problems I wouldn't have let anyone see the code in >the first place. :)
I only thought that because I remembered seeing you mention a couple but I was obviously wrong :) Andi

Sara Golemon

22 years ago
> > > c) I don't think you are creating the necessary switch_free's and
other
> > > frees when jumping out of a scope unexpectedly. > > > > >Entirely possible. The tests I've run don't complain but that doesn't
mean
> >something bad isn't happening. >
Thanks for the pointers, I at least see what I need to be exploring now (though I havn't sat down to unfold its meaning yet). Cetainly the implementation given earlier needs work whether its to make it work as advertised or in the more limited fashion suggested in other posts. I intend to put some work into it regardless of whether it'll be included or not. As I mentioned originally, this entire effort was meant as a learning exercise, and it's doing that job. If it's used: great. If not, it'll just stay where it is and those who want it can still patch it in. -Sara

Jacques Marneweck

22 years ago
Hi Sara, I can see where I can similfy certain code on a project I coded which would reduce some major ugly code. Sure I could have rewritten the code in c but I prefered having something easier to maintain in the early hours of the morning. Drop me a line where I can find the updated patches once they have been released. Regards --jm On Fri, 30 Jul 2004 21:24:20 -0700, Sara Golemon <pollita@php.net> wrote:
> > > > c) I don't think you are creating the necessary switch_free's and > other > > > > frees when jumping out of a scope unexpectedly. > > > > > > >Entirely possible. The tests I've run don't complain but that doesn't > mean > > >something bad isn't happening. > > > Thanks for the pointers, I at least see what I need to be exploring now > (though I havn't sat down to unfold its meaning yet). Cetainly the > implementation given earlier needs work whether its to make it work as > advertised or in the more limited fashion suggested in other posts. > > I intend to put some work into it regardless of whether it'll be included or > not. As I mentioned originally, this entire effort was meant as a learning > exercise, and it's doing that job. If it's used: great. If not, it'll just > stay where it is and those who want it can still patch it in. > > -Sara > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- Jacques Marneweck http://www.powertrip.co.za/blog/

Andrey Hristov

22 years ago
Sara Golemon wrote:
> Thanks for the pointers, I at least see what I need to be exploring now > (though I havn't sat down to unfold its meaning yet). Cetainly the > implementation given earlier needs work whether its to make it work as > advertised or in the more limited fashion suggested in other posts. > > I intend to put some work into it regardless of whether it'll be included or > not. As I mentioned originally, this entire effort was meant as a learning > exercise, and it's doing that job. If it's used: great. If not, it'll just > stay where it is and those who want it can still patch it in. >
How does the GOTO implementation handle this script1.php <?php do_some_stuff(); include script2.php; label: echo "Hello" ?> script2.php: <?php declare_some_funcs(); .... some code ... if (some_cond) { goto label; } .... other code.... ?> I think is again local scope because it's in main() Concise, jumping between files that happen to be included. thanks, Andrey

Andi Gutmans

22 years ago
At 09:24 PM 7/30/2004 -0700, Sara Golemon wrote:
> > > > c) I don't think you are creating the necessary switch_free's and >other > > > > frees when jumping out of a scope unexpectedly. > > > > > > >Entirely possible. The tests I've run don't complain but that doesn't >mean > > >something bad isn't happening. > > >Thanks for the pointers, I at least see what I need to be exploring now >(though I havn't sat down to unfold its meaning yet). Cetainly the >implementation given earlier needs work whether its to make it work as >advertised or in the more limited fashion suggested in other posts. > >I intend to put some work into it regardless of whether it'll be included or >not. As I mentioned originally, this entire effort was meant as a learning >exercise, and it's doing that job. If it's used: great. If not, it'll just >stay where it is and those who want it can still patch it in.
Sara, Feel free to email me personally and I can help you out and give you advice on what you should be looking at. Andi

Unnamed Person

22 years ago
Andi Gutmans <andi@zend.com> writes:
> I don't think we should be using computed targets. It'd be more of a > nightmare than sexy. I prefer doing as much at compile-time as possible and > I don't think that allowing indirect goto's would lead to anything than > chaos. Most arguments in favor of goto were for circumstances where this > would not be required. (And yes, even if we pre-compute what we can and add > the hash and opcode for the instances we can't pre-compute I think it's a > very bad idea). I feel about 1000 times stronger about that than goto :)
If you really, really, really wanted to do such a thing, you could still do: eval("goto foo$bar;"); to get the same effect, right? Just to add my 2 cents, I "grew up" in the early days of structured programming, while Pascal was gaining in popularity. I was taught to never use goto. I've been developing code for over 25 years now, and although I still tend not to use goto (by its various names) in any of the many languages I use (other than possibly assembly language :-), I do find occasional appropriate use for it, particularly for error handling. In fact, some of my recent PHP development could have benefited in simplicity of code by having goto available. I vote +1 for goto with static labels (computed at compile time), and -1 for dynamic labels. I would, however, like to see the above eval kludge work, for consistency of the eval operation. Derrell

Derick Rethans

22 years ago
On Tue, 3 Aug 2004 Derrell.Lipman@UnwiredUniverse.com wrote:
> Andi Gutmans <andi@zend.com> writes: > > > I don't think we should be using computed targets. It'd be more of a > > nightmare than sexy. I prefer doing as much at compile-time as possible and > > I don't think that allowing indirect goto's would lead to anything than > > chaos. Most arguments in favor of goto were for circumstances where this > > would not be required. (And yes, even if we pre-compute what we can and add > > the hash and opcode for the instances we can't pre-compute I think it's a > > very bad idea). I feel about 1000 times stronger about that than goto :) > > If you really, really, really wanted to do such a thing, you could still do: > > eval("goto foo$bar;"); > > to get the same effect, right?
Hmm, depends on how it's implemented. It will most likely not work I guess. Derick

Edin Kadribasic

22 years ago
On Friday, Jul 30, 2004, at 20:47 Europe/Copenhagen, Andi Gutmans wrote:
> No it doesn't. As I mentioned Sara's implementation is extremely > flawed. So yes there is a technical issue here beside a semantic > issue. And the C# limitation might very well apply in PHP too.
From what Sara said in an earlier post her goto implementation is working only in a local scope. And my testing of her patch confirms it. It even behaves nicely when mixed with exceptions. So I wonder what is this "extreme flaw"? Edin

Zeev Suraski

22 years ago
My 2c - we shouldn't discuss the implementation in the same context as whether we should have it, because it moves the focus away from the source of the problem, which is not implementation. We're way beyond the times when we add something to PHP just because we can... I'm not saying we shouldn't discuss it, just not in the same thread. Zeev At 22:06 30/07/2004, Edin Kadribasic wrote:

Edin Kadribasic

22 years ago
On Friday, Jul 30, 2004, at 21:16 Europe/Copenhagen, Zeev Suraski wrote:
> My 2c - we shouldn't discuss the implementation in the same context as > whether we should have it, because it moves the focus away from the > source of the problem, which is not implementation. We're way beyond > the times when we add something to PHP just because we can... I'm not > saying we shouldn't discuss it, just not in the same thread.
I pretty much fail to see the reason to discuss this with you as you have more or less already vetoed it. No amount of arguments on how useful this tool is in certain situation is is going to convince you, isn't it? It is after all you who has such delicate sense of what are the needs of "the community". Edin

Zeev Suraski

22 years ago
At 22:26 30/07/2004, Edin Kadribasic wrote:
>On Friday, Jul 30, 2004, at 21:16 Europe/Copenhagen, Zeev Suraski wrote: > >>My 2c - we shouldn't discuss the implementation in the same context as >>whether we should have it, because it moves the focus away from the >>source of the problem, which is not implementation. We're way beyond the >>times when we add something to PHP just because we can... I'm not saying >>we shouldn't discuss it, just not in the same thread. > >I pretty much fail to see the reason to discuss this with you as you have >more or less already vetoed it. No amount of arguments on how useful this >tool is in certain situation is is going to convince you, isn't it? It is >after all you who has such delicate sense of what are the needs of "the >community".
I think it's a shame you resort to sarcasm instead of actually responding the points I (and others) are making. I went over the thread and most of what I could find was references to other places with examples that show why GOTO is so necessary, but couldn't actually find too many of these places. I think it would help if you (or anybody else) tried to present the case for GOTO in a clear way, giving a set of situations where you believe that GOTO is necessary and cannot be resolved in a different, equivalently-good way, while answering the issues that I (and others) have raised, instead of discounting them as irrelevant. WTF factor and likelihood of abuse ARE factors, so far the only response from the pro-GOTO camp is that we should just ignore these factors, which is IMHO not an acceptable approach. In my opinion the pro-GOTO camp doesn't have real answers to these concerns, which is exactly why I believe that GOTO is not a good idea for PHP. If you (or any of the other pro-GOTO people) cannot address these concerns in a convincing way, then you're right - there's no point discussing it, at least not beyond the context of an academic implementation discussion. And please, stop the 'dictator!' accusations. If whatever came out of my mouth was immediately implemented in PHP, we'd have libxml2 bundled and SOAP support built-in (just two examples, there are plenty more, and that's just fine). Zeev

Edin Kadribasic

22 years ago
Zeev Suraski wrote:
> At 22:26 30/07/2004, Edin Kadribasic wrote: > >> On Friday, Jul 30, 2004, at 21:16 Europe/Copenhagen, Zeev Suraski wrote: >> >>> My 2c - we shouldn't discuss the implementation in the same context >>> as whether we should have it, because it moves the focus away from >>> the source of the problem, which is not implementation. We're way >>> beyond the times when we add something to PHP just because we can... >>> I'm not saying we shouldn't discuss it, just not in the same thread. >> >> >> I pretty much fail to see the reason to discuss this with you as you >> have more or less already vetoed it. No amount of arguments on how >> useful this tool is in certain situation is is going to convince you, >> isn't it? It is after all you who has such delicate sense of what are >> the needs of "the community". > > > I think it's a shame you resort to sarcasm instead of actually > responding the points I (and others) are making. I went over the thread > and most of what I could find was references to other places with > examples that show why GOTO is so necessary, but couldn't actually find > too many of these places.
Ok if you insist I'll copy and paste example where I said I missed goto very much in my several years of using PHP: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); $res=do_stuff(); if(!$res) goto err_out; $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) goto err_out; $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) goto err_out; return true; err_out: free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); return false; } [snip]
> And please, stop the 'dictator!' accusations. If whatever came out of > my mouth was immediately implemented in PHP, we'd have libxml2 bundled > and SOAP support built-in (just two examples, there are plenty more, and > that's just fine).
You wanted SOAP promoted from PECL to the main distro which has happened. Libxml2 is built-in on Windows along with the lastest PHP XML extensions. Including libxml2 source in the source distro presented some problems that required some effort to be solved. I don't remember you our anybody else willing to put some work into this. Edin

Andi Gutmans

22 years ago
At 09:53 PM 7/30/2004 +0200, Edin Kadribasic wrote: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); do { $res=do_stuff(); if(!$res) break; $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) break; $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) break; return true; } while (0); free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); return false; }

Edin Kadribasic

22 years ago
Andi Gutmans wrote: [snip] I didn't say it cannot be done with goto emulation (and abuse of a feature on par with switch(true)). What I mean is that using the real thing makes code more readable and maintinable. Add another level of nesting and do/while becomes even harder to read. Edin

Andi Gutmans

22 years ago
At 10:31 PM 7/30/2004 +0200, Edin Kadribasic wrote:
>Andi Gutmans wrote: > >[snip] > >I didn't say it cannot be done with goto emulation (and abuse of a feature >on par with switch(true)). What I mean is that using the real thing makes >code more readable and maintinable. Add another level of nesting and >do/while becomes even harder to read.
I just sent it out because I wanted people to see what it looks like. I think it's sexy :) Andi

Hartmut Holzgraefe

22 years ago
Andi Gutmans wrote: so you are replacing the question "where does it go to" that can be answered with a string search wiht "where does it break to" This one alone justifies at least labeled breaks as JAVA has them and that are a kind of restricted GOTO (as you can also break out of an if) The JAVA approach is even superior to PHPs "break n;" where n has to be an integer and you have to be very carefull to not wrap another loop around the break but within the loop supposed to be broken
> At 09:53 PM 7/30/2004 +0200, Edin Kadribasic wrote: > function pseudocode() > { > $a=allocate_resource_z(); > $b=allocate_resource_y(); > > do { > $res=do_stuff(); > if(!$res) > break; > > $c=allocate_resource_x(); > $res=do_more_stuff(); > if(!$res) > break; > > $d=allocate_resource_foo(); > $res=do_even_more_stuff(); > if(!$res) > break; > > return true; > } while (0); > > free_resouce($a); > free_resouce($b); > if(isset($c)) free_resouce($c); > if(isset($d)) free_resouce($c); > > return false; > } >
-- Hartmut Holzgraefe <hartmut@php.net>

Paul G

22 years ago
----- Original Message ----- From: "Andi Gutmans" <andi@zend.com> To: "Edin Kadribasic" <edink@emini.dk>; "Zeev Suraski" <zeev@zend.com> Cc: "Jeff Moore" <jeff@procata.com>; <ilia@prohost.org>; <internals@lists.php.net> Sent: Friday, July 30, 2004 4:13 PM Subject: Re: [PHP-DEV] GOTO operator
> At 09:53 PM 7/30/2004 +0200, Edin Kadribasic wrote: > function pseudocode() > { > $a=allocate_resource_z(); > $b=allocate_resource_y(); > > do { > $res=do_stuff(); > if(!$res) > break; > > $c=allocate_resource_x(); > $res=do_more_stuff(); > if(!$res) > break; > > $d=allocate_resource_foo(); > $res=do_even_more_stuff(); > if(!$res) > break; > > return true; > } while (0); > > free_resouce($a); > free_resouce($b); > if(isset($c)) free_resouce($c); > if(isset($d)) free_resouce($c); > > return false; > }
edin didn't copy that from my mail, but do_stuff() was meant to be a placeholder for an arbitrary amount of code, even inline. what happens if do_stuff() is a while loop, or if do_more_stuff() is actually 20 lines of relatively strongly nested code? this do-while kludge gets very hairy very fast. i'm somewhat confuzzled why you, of all people, are advocating such mutilation of do-while(), which is *abuse* of the construct. mutilating one construct to emulate another construct, which won't be implemented because it could be abused and mutilated, just doesn't compute for me. i am onboard with the no-goto-out-of-local-scope argument, which the do-while() kludge imposes as well. no reason this limitation can not be implemented, if it isn't already (it is afair), in the patch. paul

Zeev Suraski

22 years ago
At 22:53 30/07/2004, Edin Kadribasic wrote:
>[snip]
And can you explain why you can't solve this with exceptions in 2 minutes?
>>And please, stop the 'dictator!' accusations. If whatever came out of my >>mouth was immediately implemented in PHP, we'd have libxml2 bundled and >>SOAP support built-in (just two examples, there are plenty more, and >>that's just fine). > >You wanted SOAP promoted from PECL to the main distro which has happened.
Right, I don't remember there was any opposition to that either, but there was certainly some for enabling it by default, which I think makes perfect sense. Hence, one example where my dictatorial skills failed me ;)
> Libxml2 is built-in on Windows along with the lastest PHP XML extensions.
Oh come on, you of all people should know that Windows is a different beast, and libxml2 is not the only example. Since I truly don't want ot revive this discussion, suffice to say that where we are now is not at all where I think we should be as far as libxml bundling, and it's not because of lack of volunteers. Just watch the list heat up 10x more if I say something to the effect that I'm willing to do it or put somebody on the job of doing it - we'll miss the nice-going GOTO discussion. Relax people, I said IF, I didn't actually say it! ;) Zeev

Robert Cummings

22 years ago
On Thu, 2004-07-29 at 20:10, Andrey Hristov wrote:
> Robert Cummings wrote: > > On Thu, 2004-07-29 at 17:25, Timm Friebe wrote: > > > >>On Thu, 2004-07-29 at 04:12, Sara Golemon 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. | `------------------------------------------------------------'

Andrey Hristov

22 years ago
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

Sara Golemon

22 years ago
> do { > .....code... > if (something) break; > ...code.... > } while (0); > ...cleanup code... >
Are you suggesting a hack is better than the real thing? -Sara

Andrey Hristov

22 years ago
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

Jason Garber

22 years ago
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

Paul G

22 years ago
----- 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

Andrey Hristov

22 years ago
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 :)

Jason Garber

22 years ago
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

Jan Dittmer

22 years ago
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

Andrey Hristov

22 years ago
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 :)

David Chen

22 years ago
"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).

DvDmanDT

22 years ago
> 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.
Indeed, but the original point was to make it easier to read.. Now, what will make most sense to a newbie, this or the goto example this tries to replace?
> $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 > }
My opinion would be that goto isn't needed with the do..while() statement.. But on the other hand.. Neither for(), while() or do..while() would be needed with goto, would they? Is the example above or nested do..while()'s easier to read and maintain than the same code using goto? And with the rules everyone want with goto, you couldn't really mess anything up more than you already can do with do..while.. Right? Ofcorse it could create unreadable code, but then.. What couldn't? The logic of goto is simple. Almost anyone can understand it without reading the manual. What is a newbie more likely to abuse or use in a wrong way? Well, seems to me like he will more likely mess up something he doesn't understand. Also. The main reason for not adding goto has been that it can be abused. Let's see. It exists in C, C++, C#, Python, Ada, Lisp, Pascal and who could list them all? Now.. How much does people abuse goto in those languages? Not very much as far as I can see (to be honest, I didn't think it existed in anything else than Basic until I read this topic, but then, I'm not too experienced with programming).. So why does everyone think it'll be more abused in PHP? Just the comments from an average PHP user.
-- // DvDmanDT MSN: dvdmandt¤hotmail.com Mail: dvdmandt¤telia.com

Steph

22 years ago
> My opinion would be that goto isn't needed with the do..while() > statement.. > But on the other hand.. Neither for(), while() or do..while() would be > needed with goto, would they?
I learned a language called PHP. It contains for(), while() and do..while(). I've been writing scripts that contain those expressions for some years now.

Hartmut Holzgraefe

22 years ago
Robert Cummings wrote:
> 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.
Even PASCAL, the mother of "structured code" languages, has it!
-- Hartmut Holzgraefe <hartmut@php.net>

Joseph Lee

22 years ago
Hartmut Holzgraefe wrote:
> Robert Cummings wrote: >> 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. > >Even PASCAL, the mother of "structured code" languages, has it!
Python too! ;) http://www.entrian.com/goto/ ;)

Ilia A.

22 years ago
On July 29, 2004 05:25 pm, Timm Friebe wrote:
> 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

Jeremy S. Johnstone

22 years ago
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 On Wednesday 28 July 2004 09:12 pm, Sara Golemon wrote:

Derick Rethans

22 years ago
On Wed, 28 Jul 2004, Sara Golemon 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. 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
I think we should make it allow constant label names only, doing it dynamically is just too confusing to read later on. Derick