Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-20-2009, 01:26 PM Goto
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
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.

__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
 
Register now for full access!
Old 10-20-2009, 01:30 PM Re: Goto
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,514
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Nooooooooooooooooooooooooooooooooooooooooooooooooo ooooo!!!!!!!!!!!
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
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
Missing! presumed drunk.

Posts: 41,514
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Had to pause for a breath near the end
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
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
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
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

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
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

Posts: 2,781
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";
}
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-20-2009, 05:29 PM Re: Goto
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
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

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-20-2009, 06:11 PM Re: Goto
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,514
Name: Chris Hirst
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
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
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
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.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
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.46679 seconds with 12 queries