TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   The Lounge (http://www.talkphp.com/lounge/)
-   -   Php5.3:: Goto...wtf??? (http://www.talkphp.com/lounge/4818-php5-3-goto-wtf.html)

JaoudeStudios 08-06-2009 07:39 AM

Php5.3:: Goto...wtf???
 
PHP5.3 comes with lots of great improvements: namespaces etc...but it also comes with GOTO statements (reminds me of back in the day of BASIC), certainly not an improvement as this is open to abuse by a lazy developer who could easily create unmanageable code!


Ahhhhhhh.....!!!!!

Note to PHP contributers: Lets improve PHP's multi-threading and daemonisation NOT f**king GOTO statements (even if they are improved GOTO statements)!

sketchMedia 08-06-2009 10:16 AM

Argh!! GOTO ... just ARGH!
A little pic we have on the Tech team page of our intranet (oddly it seems to be on the PHP manual too!):

http://xkcd.com/292/

All joking aside, people criticize PHP for including it, when many respected languages implement them in one way or another. C for example has had it since the dawn of time (literally) and that's the most respected language you can find. It may surprise people that we have had types of goto in PHP for years, switch/break etc etc.
PHP Code:

for($i=0$i10; ++$i)
{
    for(
$j=0$j 200; ++$j)
    {
        if(
$j == 20) { break };        
    }
}

switch(
$goto)
{
    case 
'cheese':
        
//do stuff
        
break;    


Did you know that the linux kernal uses extensive use of it?
http://kerneltrap.org/node/553/2131
What's good for Linus is good for all!

Quote:

this is open to abuse by a lazy developer who could easily create unmanageable code!
I totally agree, personally I don't much care for goto's I've seen some truly horrifying code using them, however I do still believe that is an issue with the programmer not the tool. A bad programmer will write bad spaghetti code irrespective of goto's availability. I have seen some equally as horrifying code without GOTO's.

Salathe 08-06-2009 02:53 PM

Quote:

Originally Posted by sketchMedia (Post 27567)
I do still believe that is an issue with the programmer not the tool. A bad programmer will write bad spaghetti code irrespective of goto's availability. I have seen some equally as horrifying code without GOTO's.

I'm definitely on this side of the fence. Goto in PHP is just another tool to get the job done; if poor programmers jump on every (mis-)opportunity to use this "new feature" then that is their problem and I hope you don't have to deal with their mess which would have been a mess anyway with or without goto.

Village Idiot 08-06-2009 03:18 PM

There is no "good" use for goto. Absolutely needing to use it means you don't understand structured programming.

Enfernikus 08-06-2009 03:41 PM

There aren't alot of cases where you absolutely need to make use of any one particular feature in a language to accomplish a single task, we've many tools to accomplish the same thing. Goto's are just another feature and if we feel the need to use it than we may and if the code goes spaghetti, it's the programmer's fault and nothing to do with the existence of "goto" a sphagetti-coder will produce the same mess regardless of the existence of goto.

Village Idiot 08-06-2009 06:08 PM

Quote:

Originally Posted by Enfernikus (Post 27571)
There aren't alot of cases where you absolutely need to make use of any one particular feature in a language to accomplish a single task, we've many tools to accomplish the same thing. Goto's are just another feature and if we feel the need to use it than we may and if the code goes spaghetti, it's the programmer's fault and nothing to do with the existence of "goto" a sphagetti-coder will produce the same mess regardless of the existence of goto.

But goto is different, there is no good use for that command opposed to others that have lateral alternatives. I'm not saying that taking it away will fix coding, I'm saying it is bad to add because it can only hurt.

Kalle 08-07-2009 09:56 PM

goto in php isnt THAT bad, its a construct to ease development, in php its refered as the "jump label operator", but it really is a kind of goto but limited. In PHP you cannot jump inside a loop or to another scope for example. If you don't like it, then fine don't use it, simple as that. Rasmus have some slides and theres various videos with "Whats new in 5.3" by him, where he greatly explains it, what it is, what its not etc.

However goto is useful in some cases, for example when writing complex parsers, like the Engine which basiclly is a skeleton filled with rules thats turned into a complex parser with goto using tools like flex or re2c. So its a useful construct for such generated code for example.

Quote:

Note to PHP contributers: Lets improve PHP's multi-threading and daemonisation NOT f**king GOTO statements (even if they are improved GOTO statements)!
If you want that improved, then post it to the mailing list, even creating a patch for it or see if others are interested in that feature, or put it on our bug tracker (bugs.php.net, mark it as a "Feature/Change Request"). Take a look at http://php.net/mailinglists and subscribe to internals and post a topic and see what others think, theres nothing like breaking the silence and stop complaing about features that may not appeal to you :)

ETbyrne 08-07-2009 10:37 PM

It's not really all that bad, just don't use it if you don't like it. I can see how it would promote bad code practices, but I can also see how it would be useful for something like a multi-level break.

PHP Code:

// $x is a multi-dimensional array of data..

foreach($x as $y)
{
    foreach(
$y as $z)
    {
        if(
$z == 'your mom')
        {
            goto 
sweet;
        }
    }
}

sweet

Then again you could just use break 2; ...

JaoudeStudios 08-08-2009 09:01 AM

Quote:

Originally Posted by Enfernikus (Post 27571)
There aren't alot of cases where you absolutely need to make use of any one particular feature in a language to accomplish a single task, we've many tools to accomplish the same thing. Goto's are just another feature and if we feel the need to use it than we may and if the code goes spaghetti, it's the programmer's fault and nothing to do with the existence of "goto" a sphagetti-coder will produce the same mess regardless of the existence of goto.

Here here!

Well said!

Basically...a note to everyone (including myself), dont produce bad code :-P


All times are GMT. The time now is 03:17 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0