goto label

This is a discussion on goto label within the PHP General forums, part of the PHP Programming Forums category; Hi all, I was wondering, if there's any way to achieve 'goto "label":' using PHP Thanx for ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-08-2003
Nitin
 
Posts: n/a
Default goto label

Hi all,

I was wondering, if there's any way to achieve 'goto "label":' using PHP

Thanx for ur time

Nitin
Reply With Quote
  #2 (permalink)  
Old 12-09-2003
Justin Patrin
 
Posts: n/a
Default Re: goto label

Nitin wrote:

> Hi all,
>
> I was wondering, if there's any way to achieve 'goto "label":' using PHP
>
> Thanx for ur time
>
> Nitin


goto is a very old and broken way of coding. If you ever find yourself
in need of a goto, you should re-evaluate how you're doing things. If
you're having trouble finding out how to do it better, just ask here. :-)

--
paperCrane <Justin Patrin>
Reply With Quote
  #3 (permalink)  
Old 12-09-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] goto label

* Thus wrote Nitin (nitinmehta@kappa.net.in):
> Hi all,
>
> I was wondering, if there's any way to achieve 'goto "label":' using PHP


The closest you'll get to label's in php is the break statement.


while (loop) {

while (loop) {
break 2; // leave 2 loops
}

while (loop) {
break; // leave this loop
}

}



Curt
--
If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP
Reply With Quote
  #4 (permalink)  
Old 12-09-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] Re: goto label

On Tue, 2003-12-09 at 00:32, Justin Patrin wrote:
> Nitin wrote:
>
> > Hi all,
> >
> > I was wondering, if there's any way to achieve 'goto "label":' using PHP
> >
> > Thanx for ur time
> >
> > Nitin

>
> goto is a very old and broken way of coding. If you ever find yourself
> in need of a goto, you should re-evaluate how you're doing things. If
> you're having trouble finding out how to do it better, just ask here. :-)


Goto <line number> is a very broken way of coding. Goto <label> is a
very useful and structured way of coding especially when creating fast
FSMs for parsing. I was a little disappointed a few months ago when I
found that PHP didn't support the goto label syntax since it would have
provided the most elegant solution.

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. |
`------------------------------------------------------------'
Reply With Quote
  #5 (permalink)  
Old 12-09-2003
Justin Patrin
 
Posts: n/a
Default Re: [PHP] Re: goto label

Robert Cummings wrote:

> On Tue, 2003-12-09 at 00:32, Justin Patrin wrote:
>
>>Nitin wrote:
>>
>>
>>>Hi all,
>>>
>>>I was wondering, if there's any way to achieve 'goto "label":' using PHP
>>>
>>>Thanx for ur time
>>>
>>>Nitin

>>
>>goto is a very old and broken way of coding. If you ever find yourself
>>in need of a goto, you should re-evaluate how you're doing things. If
>>you're having trouble finding out how to do it better, just ask here. :-)

>
>
> Goto <line number> is a very broken way of coding. Goto <label> is a
> very useful and structured way of coding especially when creating fast
> FSMs for parsing. I was a little disappointed a few months ago when I
> found that PHP didn't support the goto label syntax since it would have
> provided the most elegant solution.
>
> Cheers,
> Rob.


goto anywhere is broken. For instance, goto-ing out of loops and
functions, or into one function from another causes untold grief to the
language developer and makes it very hard to read the code. Then there's
using goto into and out of class functions, which is even worse.

In truth, goto has no place in a higher level programming language.
Anything that can be done with goto can be done without it and (IMHO)
more elegantly.

--
paperCrane <Justin Patrin>
Reply With Quote
  #6 (permalink)  
Old 12-09-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] Re: goto label

On Tue, 2003-12-09 at 00:51, Justin Patrin wrote:
> Robert Cummings wrote:
> >
> > Goto <line number> is a very broken way of coding. Goto <label> is a
> > very useful and structured way of coding especially when creating fast
> > FSMs for parsing. I was a little disappointed a few months ago when I
> > found that PHP didn't support the goto label syntax since it would have
> > provided the most elegant solution.
> >
> > Cheers,
> > Rob.

>
> goto anywhere is broken. For instance, goto-ing out of loops and
> functions, or into one function from another causes untold grief to the
> language developer and makes it very hard to read the code. Then there's
> using goto into and out of class functions, which is even worse.


As I said that all depends on how it is used. Anyone can write
unreadable code regardless of whether the language supports the goto
statement. Also since PHP is strongly based on C, you'll notice that the
C language does not allow cross function jumping via goto. Goto must
jump to a label defined in the same function, so your second argument in
this case is invalid. As someone who has implemented my own language, I
can tell you I had absolutely no grief implementing a goto <label>
system.

> In truth, goto has no place in a higher level programming language.


This is your opinion, please feel free to qualify it.

> Anything that can be done with goto can be done without it and (IMHO)
> more elegantly.


Yes anything that can be done with goto can be done without, but the
whether it is more elegant strongly depends on what your goal is and how
that goal can be achieved. Here's something you should do to properly
open your eyes to the utility of the goto <label> statement.

cd /YOUR_PHP_INSTALLATION_SOURCE/
grep -rE 'goto [_[:alnum:]]+;' *

In my installation alone there are 1522 instances of goto used. And
really I don't consider PHP that much higher level a language than C,
although it does provide plenty of high level functions.

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. |
`------------------------------------------------------------'
Reply With Quote
  #7 (permalink)  
Old 12-09-2003
Viraj Kalinga Abayarathna
 
Posts: n/a
Default Re: [PHP] Re: goto label

if you are porting an old programme, try using "SWITCH", some time back i
successfully ported a lengthy code in to PHP which had many "GOTO"s .

Viraj

note: also, i had to use some parameter passing mechanism.




Justin Patrin wrote:

> Nitin wrote:
>
>> Hi all,
>>
>> I was wondering, if there's any way to achieve 'goto "label":' using PHP
>>
>> Thanx for ur time
>>
>> Nitin

>
>
> goto is a very old and broken way of coding. If you ever find yourself
> in need of a goto, you should re-evaluate how you're doing things. If
> you're having trouble finding out how to do it better, just ask here. :-)
>

Reply With Quote
  #8 (permalink)  
Old 12-09-2003
Bogdan Stancescu
 
Posts: n/a
Default Re: [PHP] Re: goto label

Justin Patrin wrote:
> Robert Cummings wrote:
>
>> Goto <line number> is a very broken way of coding. Goto <label> is a
>> very useful and structured way of coding especially when creating fast
>> FSMs for parsing. I was a little disappointed a few months ago when I
>> found that PHP didn't support the goto label syntax since it would have
>> provided the most elegant solution.
>>

> goto anywhere is broken. For instance, goto-ing out of loops and
> functions, or into one function from another causes untold grief to the
> language developer and makes it very hard to read the code. Then there's
> using goto into and out of class functions, which is even worse.
>
> In truth, goto has no place in a higher level programming language.
> Anything that can be done with goto can be done without it and (IMHO)
> more elegantly.


Robert, I know your grief, been there, I know how it feels. I started my
childhood with BASIC, which was /the/ "GOTO" programming language,
learned Turbo Pascal when I was a teenager, and continued to use GOTO's
(Pascal discourages but doesn't disallow GOTO's, so I was still able to
"cheat" when "there was a need for it"). Well, later on when I started
finding out how major projects are being developed, what structured
programming really means and so on, I felt the way you feel now:
cheated. "Why in God's name is GOTO bad? It's SO useful! They're mad!"
Well, it simply isn't true -- the problem is that you have to change
your mindset about programming, try to really structure the way you see
a program, break it into efficient stand-alone functions, group those in
classes, etc, and you'll see that there *is* no need for GOTO, ever. You
do need to break out of loops, you do need to "short" a loop when a
condition is met, you do need to break out of switches, if branches and
the lot - but those tools you have in PHP. GOTO is not needed and
harmful. Even simply learning to program without GOTO will coerce you
into saner code.

Sorry if my message sounded melodramatic or something, I remembered the
frustration feeling so strongly from your message that I wanted to
reinforce the other people's messages with a personal "testimonial" if
you wish.

Bogdan
Reply With Quote
  #9 (permalink)  
Old 12-09-2003
John Nichel
 
Posts: n/a
Default Re: [PHP] Re: goto label

Justin Patrin wrote:

> Nitin wrote:
>
>> Hi all,
>>
>> I was wondering, if there's any way to achieve 'goto "label":' using PHP
>>
>> Thanx for ur time
>>
>> Nitin

>
>
> goto is a very old and broken way of coding. If you ever find yourself
> in need of a goto, you should re-evaluate how you're doing things. If
> you're having trouble finding out how to do it better, just ask here. :-)
>


Right, use GOSUB instead. ;)

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
Reply With Quote
  #10 (permalink)  
Old 12-09-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] Re: goto label

On Tue, 2003-12-09 at 08:14, Bogdan Stancescu wrote:
>
> Robert, I know your grief, been there, I know how it feels. I started my
> childhood with BASIC, which was /the/ "GOTO" programming language,
> learned Turbo Pascal when I was a teenager, and continued to use GOTO's
> (Pascal discourages but doesn't disallow GOTO's, so I was still able to
> "cheat" when "there was a need for it"). Well, later on when I started
> finding out how major projects are being developed, what structured
> programming really means and so on, I felt the way you feel now:
> cheated. "Why in God's name is GOTO bad? It's SO useful! They're mad!"
> Well, it simply isn't true -- the problem is that you have to change
> your mindset about programming, try to really structure the way you see
> a program, break it into efficient stand-alone functions, group those in
> classes, etc, and you'll see that there *is* no need for GOTO, ever. You
> do need to break out of loops, you do need to "short" a loop when a
> condition is met, you do need to break out of switches, if branches and
> the lot - but those tools you have in PHP. GOTO is not needed and
> harmful. Even simply learning to program without GOTO will coerce you
> into saner code.
>
> Sorry if my message sounded melodramatic or something, I remembered the
> frustration feeling so strongly from your message that I wanted to
> reinforce the other people's messages with a personal "testimonial" if
> you wish.


Ummmm, I rarely use the goto statement, and I do not advocate it for
regular everyday coding. I do know the difference between well
structured code and otherwise. What I did say, is that goto <label> has
it's uses, and sometimes it IS the best solution. Just because someone
tells you something is bad, doesn't mean to say it is always bad. It's
like someone saying salt is bad for you, and so you never take salt
again and die from salt deficiency. People really need to change their
mindset about being sheeple (yes sheep people) and blindly following
preached dogma.

I don't mind your message sounding melodramatic, but it doesn't explain
in any way why goto shouldn't be used. It just asserts that you found
out how major projects are done, which IMHO doesn't lend support to why
one shouldn't use the goto statement. In actual fact it makes me think
you are missing a few points. For instance properly structured
programming is often about the functions, objects, and methods, not
about the code within a function that performs the logic. For this
reason the use of goto statements within a given function that
facilitates faster cleaner code is sometimes the best solution not to
mention its contents can be considered a black box by the user of the
function. Also your response seems to indicate that you think I am a
newbie coder, well that would be a bit of an oversight. I've been coding
for over 10 years (some hobby, some academic, and some professional)
using many different styles (functional, procedural, and OOP) and so I
am plenty aware of design paradigms, re-usability, and clarity. I also
have extensive experience refactoring old spaghetti code.

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. |
`------------------------------------------------------------'
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0