Re: Alternative to goto

2011-04-16 Thread Peter Scott
On Fri, 15 Apr 2011 08:48:10 -0400, shawn wilson wrote: > but, sense it is jumping to a different place in the stack, isn't it > more efficient than doing the above mentioned > > my $done = 0; > while( !$done ){ >$done = 1 if( contition ); >do_work; > } > > vs > > for(;;) { >goto DON

Re: Alternative to goto

2011-04-15 Thread Brandon McCaig
On Thu, Apr 14, 2011 at 11:27 PM, Peter Scott wrote: >  The perldoc for > goto says he has never found a reason to use it. Though to be complete: perldoc -f goto said: > The author of Perl has never felt the need to use this form of > "got

Re: Alternative to goto

2011-04-15 Thread Rob Dixon
On 15/04/2011 13:48, shawn wilson wrote: but, sense it is jumping to a different place in the stack, isn't it more efficient than doing the above mentioned my $done = 0; while( !$done ){ $done = 1 if( contition ); do_work; } vs for(;;) { goto DONE if( contition ); do_work; } l

Re: Alternative to goto

2011-04-15 Thread Shawn H Corey
On 11-04-15 08:48 AM, shawn wilson wrote: my $done = 0; while( !$done ){ $done = 1 if( contition ); do_work; } vs for(;;) { goto DONE if( contition ); do_work; } label DONE; for(;;){ do_work; goto DONE if( condition ); } DONE: The first loop always executes `do_work` even

Re: Alternative to goto

2011-04-15 Thread Shawn H Corey
On 11-04-15 08:26 AM, Bob McConnell wrote: But "goto" is uncontrolled and ignores that context, leaving the stack and related structures in an unknown state. This is from my perspective as a long time Assembler and C programmer. Is it any different in Perl? Yes. It sets the state correctly.

Re: Alternative to goto

2011-04-15 Thread shawn wilson
On Thu, Apr 14, 2011 at 11:27 PM, Peter Scott wrote: > On Thu, 14 Apr 2011 10:47:17 -0700, sono-io wrote: > >> On Apr 14, 2011, at 10:15 AM, Uri Guttman wrote: >> >>> goto just shouldn't be in your vocabulary. there is no reason for it at >>> all in any decent language, especially perl. >> >>    

RE: Alternative to goto

2011-04-15 Thread Bob McConnell
From: Uri Guttman >> "SF" == Shlomi Fish writes: > > SF> I should note that in C "continue", "break", and a pre-mature > SF> "return" may also be considered as pseudo-gotos. > > huh? same as perl then. > I was going to stay out of this, but here I think I want to challenge this assertio

Re: Alternative to goto

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 10:47:17 -0700, sono-io wrote: > On Apr 14, 2011, at 10:15 AM, Uri Guttman wrote: > >> goto just shouldn't be in your vocabulary. there is no reason for it at >> all in any decent language, especially perl. > > I've been following this thread and I'm just curious. If g

Re: Alternative to goto

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 20:44:57 +0100, Rob Dixon wrote: > [ Good arguments about goto ] > A final note, perldoc perlsyn says > > A loop's LABEL is not actually a valid target for a goto; it's just > the name of the loop. > > and I am left wondering what this means, as I have had no problem > wri

Re: Alternative to goto

2011-04-14 Thread Uri Guttman
> "s" == sono-io writes: s> On Apr 14, 2011, at 10:15 AM, Uri Guttman wrote: >> goto just shouldn't be in your vocabulary. there is no reason for it at all in any decent language, especially perl. s>I've been following this thread and I'm just curious. If goto s>is so bad,

Re: Alternative to goto

2011-04-14 Thread Brandon McCaig
On Thu, Apr 14, 2011 at 3:11 PM, Brandon McCaig wrote: > catch: >    // Cleanup all allocated resources and ignore unallocated >    // ones (that is, no matter where in the function the goto is >    // called it should work properly and not crash the >    // application)... I forgot to mention th

Re: Alternative to goto

2011-04-14 Thread John Delacour
At 23:00 +0300 14/04/2011, Shlomi Fish wrote: In Perl, I don't encourage people using goto statements, and I did not find a use for them in Perl, yet. But I don't rule out that they have legitimate use in other languages... int alloc_stuff(struct_t * * ref) { Let's stick to Perl and stop bo

Re: Alternative to goto

2011-04-14 Thread Uri Guttman
> "BM" == Brandon McCaig writes: BM> On Thu, Apr 14, 2011 at 1:15 PM, Uri Guttman wrote: >> that can still be done very cleanly without gotos. one technique is to >> collect all the resources into a structure as you initialize. at any >> point when it fails, you return to an outer f

Re: Alternative to goto

2011-04-14 Thread Uri Guttman
> "SF" == Shlomi Fish writes: SF> Well, some use cases for goto in C: SF> 1. Breaking out of more outer loop (as there is no "continue label;" or "break SF> label;" in C: SF> SF> for (i=0 ; i < len ; i++) SF> { SF> for (j = 0 SF> { SF> if (func(i, j)

Re: Alternative to goto

2011-04-14 Thread Rob Dixon
On 14/04/2011 19:36, Shlomi Fish wrote: > > I should note that in C "continue", "break", and a pre-mature "return" may > also be considered as pseudo-gotos. Indeed. Funtionally, Perl has many keywords that transfer control to a different place in the code (next, break, continue, return, if, elsif

Re: Alternative to goto

2011-04-14 Thread Brandon McCaig
On Thu, Apr 14, 2011 at 1:15 PM, Uri Guttman wrote: >> "BM" == Brandon McCaig writes: >  BM> I often use gotos in C for error handling within a function. If >  BM> you're allocating resources and something later on fails then you >  BM> usually want (or need) to clean up those resources befor

Re: Alternative to goto

2011-04-14 Thread Shawn H Corey
On 11-04-14 02:36 PM, Shlomi Fish wrote: > On Thursday 14 Apr 2011 17:47:02 Uri Guttman wrote: > then you don't know how to code well in c. Thanks for the compliment.;-) > it may not be as nice as perl > for some flow control things but goto is never needed in c either. Thanks for avoiding

Re: Alternative to goto

2011-04-14 Thread Shlomi Fish
Hi Uri, On Thursday 14 Apr 2011 17:47:02 Uri Guttman wrote: > > "SF" == Shlomi Fish writes: > SF> On Thursday 14 Apr 2011 09:15:35 Uri Guttman wrote: > >> > "PS" == Peter Scott writes: > PS> Here is the definitive explanation: > >> http://www.cs.utexas.edu/users/EWD/ PS> ewd02xx/

Re: Alternative to goto

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 14:05:54 +0300, Shlomi Fish wrote: > Hi Uri and Peter, >> > Regarding the "Goto statement considered harmful" myth, see what I wrote > about it here: "Myth" is generally used to descibe something widely thought to be true that is in fact false. The assertion that goto is ha

Re: Alternative to goto

2011-04-14 Thread Shawn H Corey
On 11-04-14 01:47 PM, sono...@fannullone.us wrote: On Apr 14, 2011, at 10:15 AM, Uri Guttman wrote: goto just shouldn't be in your vocabulary. there is no reason for it at all in any decent language, especially perl. I've been following this thread and I'm just curious. If goto is s

Re: Alternative to goto

2011-04-14 Thread sono-io
On Apr 14, 2011, at 10:15 AM, Uri Guttman wrote: > goto just shouldn't be in your vocabulary. there is no reason for it at all > in any decent language, especially perl. I've been following this thread and I'm just curious. If goto is so bad, why did they add it to Perl? Marc -- To un

Re: Alternative to goto

2011-04-14 Thread Uri Guttman
> "BM" == Brandon McCaig writes: BM> On Thu, Apr 14, 2011 at 10:47 AM, Uri Guttman wrote: >> then you don't know how to code well in c. it may not be as >> nice as perl for some flow control things but goto is never >> needed in c either. i have seen it used and there are always >

Re: Alternative to goto

2011-04-14 Thread Shawn H Corey
On 11-04-14 12:52 PM, Brandon McCaig wrote: I often use gotos in C for error handling within a function. If you're allocating resources and something later on fails then you usually want (or need) to clean up those resources before returning. I've seen a lot of people duplicate the same cleanup c

Re: Alternative to goto

2011-04-14 Thread Brandon McCaig
(Sorry, Uri, meant to reply to the list...) On Thu, Apr 14, 2011 at 10:47 AM, Uri Guttman wrote: > then you don't know how to code well in c. it may not be as > nice as perl for some flow control things but goto is never > needed in c either. i have seen it used and there are always > better ways

Re: Alternative to goto

2011-04-14 Thread Uri Guttman
> "SF" == Shlomi Fish writes: SF> On Thursday 14 Apr 2011 09:15:35 Uri Guttman wrote: >> > "PS" == Peter Scott writes: PS> Here is the definitive explanation: >> http://www.cs.utexas.edu/users/EWD/ PS> ewd02xx/EWD215.PDF . >> >> having heard about that article for many year

Re: Alternative to goto

2011-04-14 Thread Shawn H Corey
On 11-04-14 12:57 AM, Mariano Loza Coll wrote: I have yet to find one that explains clearly the reasons arguing against its use. It's a religious thing. It is far better to hide your gotos in a state machine than to expose them to light. Example of a state machine with hidden gotos: my $do

Re: Alternative to goto

2011-04-14 Thread Shlomi Fish
Hi Uri and Peter, On Thursday 14 Apr 2011 09:15:35 Uri Guttman wrote: > > "PS" == Peter Scott writes: > PS> On Wed, 13 Apr 2011 21:57:53 -0700, Mariano Loza Coll wrote: > >> Like Owen, I've come across many a recommendation AGAINST using goto > >> in Perl. And (like Owen?), I have yet t

Re: Alternative to goto

2011-04-13 Thread Uri Guttman
> "PS" == Peter Scott writes: PS> On Wed, 13 Apr 2011 21:57:53 -0700, Mariano Loza Coll wrote: >> Like Owen, I've come across many a recommendation AGAINST using goto in >> Perl. And (like Owen?), I have yet to find one that explains clearly the >> reasons arguing against its use. If

Re: Alternative to goto

2011-04-13 Thread Peter Scott
On Wed, 13 Apr 2011 21:57:53 -0700, Mariano Loza Coll wrote: > Hi all, > >>  OC> I never bothered to learn how >>  OC> to use goto because it's deprecated (or on it's way?), but it OC> >>  seems like this would be a good place to use it.  At the same OC> >>  time, I understand that use of goto is

Re: Alternative to goto

2011-04-13 Thread Uri Guttman
> "MLC" == Mariano Loza Coll writes: MLC> Hi all, >>  OC> I never bothered to learn how >>  OC> to use goto because it's deprecated (or on it's way?), but it >>  OC> seems like this would be a good place to use it.  At the same >>  OC> time, I understand that use of goto is akin to

Re: Alternative to goto

2011-04-13 Thread Mariano Loza Coll
Hi all, >  OC> I never bothered to learn how >  OC> to use goto because it's deprecated (or on it's way?), but it >  OC> seems like this would be a good place to use it.  At the same >  OC> time, I understand that use of goto is akin to sleeping with your >  OC> sister among most programmers in th

Re: Alternative to goto

2011-04-13 Thread Uri Guttman
> "OC" == Owen Chavez writes: OC> I'm writing a script for work that navigates users through a OC> complex decision-making tree, where decisions are made based on OC> some fairly in-depth processing of data entered by the user. The OC> script runs really well, does exactly what we ne