Reply
Old 10-20-2009, 01:26 PM Goto
wayfarer07's Avatar
NYE-KEE

Posts: 3,155
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Something I forgot to include in the PHP 6 sticky:

The goto operator is available as of PHP 5.3.

__________________
Wayfarer | jQuery Tooltip Plugin | Mapbox: the jQuery Map
Freelance Jobs Available
If Google is the Coca-Cola of Web search, Bing is RC Cola
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
 
When You Register, These Ads Go Away!
Old 10-20-2009, 01:30 PM Re: Goto
chrishirst's Avatar
Super Moderator

Posts: 22,257
Location: Blackpool. UK
Trades: 0
Nooooooooooooooooooooooooooooooooooooooooooooooooo ooooo!!!!!!!!!!!
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 01:31 PM Re: Goto
chrishirst's Avatar
Super Moderator

Posts: 22,257
Location: Blackpool. UK
Trades: 0
Had to pause for a breath near the end
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 04:43 PM Re: Goto
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
When I first started coding, I proudly (and ignorantly) declared that I would always use GOTO and would never learn a language that didn't have it. I've since learned why GOTO isn't the panacea I once thought it to be, but this action makes me wonder... Why? 10's of 1000's of scripts have been written without it and it's not necessary so why take a step back? Seems more like a Microsoft move.... ::
__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is online now
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-20-2009, 05:17 PM Re: Goto
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Easy PHP Search with Opera
Posts: 1,068
Name: Matt
Location: Irvine, CA
Trades: 0
From http://www.php.net/~derick/meeting-n...ml#adding-goto

Quote:
The name "goto" is misleading, and often associated with BAD THINGS(tm). Because our proposed solution is not a real GOTO construct, we will instead reuse the "break" keyword, and extend it with a static label.
So using goto is somehow justified because it is essentially break with a static label. Isn't break in the same pool of things you should avoid?

The example they give is:
PHP Code:
<?php
for ($i 0$i 9$i++)
{
        if (
true) {
                break 
blah;
        }
        echo 
"not shown";
blah:
        echo 
"iteration $i\n";
}
?>
but doesn't it make more sense (and read better) to write that code as:

PHP Code:
<?php
for ($i 0$i 9$i++)
{
        if (
false) {
                echo 
"not shown";
        }

        echo 
"iteration $i\n";
}
?>
__________________
Tinsology | How to Post Code | EverythingDev
NullPointer is offline
Reply With Quote
View Public Profile
 
Old 10-20-2009, 05:29 PM Re: Goto
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
Thanks for that. I'd say in those 2 code segments that if there's somewhere it's supposed to stop working, then the coder probably has the wrong value for the max $i value, so instead of hack-jobbing it, the coder should be more thoughtful about the routine.

For example,
PHP Code:
<?php
$i 
0;
$j rand(0,9);
while (
$i++ < $j) {
        echo 
"iteration $i\n"

?>
or, if you want to be really complicated about it:
PHP Code:
for ($i=0$i<9$i++) {
  switch (
$i) {
    case 
0:
    case 
1:
    case 
2:
    case 
3:
    case 
4:
      echo 
"iteration $i\n";
      break;
    
//Won't do anything for $i > 4, so the equivalent of their break.
  
}

__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is online now
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-20-2009, 06:11 PM Re: Goto
chrishirst's Avatar
Super Moderator

Posts: 22,257
Location: Blackpool. UK
Trades: 0
Thing is, when used by a GOOD programmer the odd use of a goto can be a handy tool.
It can save having to raise exceptions, jump out to a cleanup routine if you need to exit an operation without executing any following code/procedures.

Unfortunately there are far more "not so good" code monkeys who will use it as an escape route and not bother with such niceties as "cleaning up", "garbage collection" or "destructor" routines and we'll see far more unstable apps and sites than we did in the days of 330 Mhz PII servers with 1Mb of RAM.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 07:16 PM Re: Goto
wayfarer07's Avatar
NYE-KEE

Posts: 3,155
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I think it's like Chris says, in theory it could be used well, or could be a quick band-aid to fix code that needs a shortcut (most likely usage), but the problem becomes readability and re-usability. What I fear the most is that beginners are going to get a hold of this and start using it everywhere, leaving a mess for the rest of us to clean up.

Like Jeremy, I used GOTO many times in my hobbyist days, playing with BASIC and Fortran. I was having lots of fun, knew nothing about structure, and it didn't matter.

I read an interview recently with the guy who started PHP (whatever his name is). He's not a big fan of OOP style programming at all, and I bet there is a moderate following among the PHP language developers that still advocate a procedural style of programming. As the PHP 5.3 release proposed class niceties like namespaces and "late static bindings", new magic methods, and more, the procedural folks probably asked, "why can't we improve the procedural part of the language also?". They made their case and commits, and were convincing enough to have their changes included for whatever reason.

I guess we'll see how it plays out. It will be a while for version 5.3.x to get used widely, as there are a few minor backwards incompatible changes that will stop hosts and companies from automatically upgrading.
__________________
Wayfarer | jQuery Tooltip Plugin | Mapbox: the jQuery Map
Freelance Jobs Available
If Google is the Coca-Cola of Web search, Bing is RC Cola
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Goto
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.14244 seconds with 13 queries