RE: Is GOTO evil?
On Thu, 6 Jan 2005, Charles K. Clarkson wrote: Chris Devers [EMAIL PROTECTED] wrote: : In [brief] defense of GOTO, for some programming it is : essential. Assembly language programming, for example. Since this is a perl list, we can safely assume the OP was not asking about assembler's goto statement, but about perl's. Well, yeah :-) Programming in assembler, huh. You're either a computer science student, very curious, or really old. :) The middle one, I guess -- I'm a few years out of school, but not *that* many years (I finished in the late 90s). The point was more that everything has a place. With `goto`, that place in my mind is low level arcana that the average Perl hacker would never get involved with, e.g. C or assembler (same difference, really). In Perl, the most common legit use of `goto` seems to be jumping out of loops, though I wouldn't put it past a clever hacker to do something useful with it in some other context, if s/he knew what they were doing. On the whole though, it seems worth avoiding if it all possible. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Is GOTO evil?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Friday 07 January 2005 00:17, zentara wrote: Like in this contrived example. foreach my $x (1..100){ foreach my $y (1..500){ foreach my $z (1..1000){ if( $x + (2 * $y) - $z = 0 ) {goto END} } $y = $x + 1; } $z = $y/4; } END: Now, I haven't done this for a while, so I hope I'm correct, but I find this a little cleaner: OUTERLOOP: foreach my $x (1..100){ foreach my $y (1..500){ foreach my $z (1..1000){ if( $x + (2 * $y) - $z = 0 ) {last OUTERLOOP;} } $y = $x + 1; } $z = $y/4; } That way it's a bit clearer what loop you are skipping, which ideally is what you are looking at when working on an algorithm, rather than where you jump to specifically. It also works better if you name the loops in a nice way (hard to do in a contrived example, of course). It achieves exactly the same thing as your goto (in probably exactly the same way internally). Note that this is just opinion, but it took me a couple of years to undo the brain-damage caused by programming exclusively in BASIC when I started coding, so I am now of the school that GOTO considered harmful (unless you really really need it, and if you think you do, there is probably a better way to do what you are trying to do) - -- Robin [EMAIL PROTECTED] JabberID: [EMAIL PROTECTED] Hostes alienigeni me abduxerunt. Qui annus est? PGP Key 0xA99CEB6D = 5957 6D23 8B16 EFAB FEF8 7175 14D3 6485 A99C EB6D -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFB3S6SFNNkhamc620RAtSUAKCh1ZZ2EYZkJqmOLEI9+ZK63FlNCgCghbLA aUx0bii9rBEXJcrE63dxsfI= =ZKVm -END PGP SIGNATURE- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Is GOTO evil?
I guess I'm really old, too (55 yrs); however, I actually saw a book (I didn't touch it though), The Art of Assembly Language Programming at Barnes Noble this afternoon. Hopefully, I've forgotten everything that I've ever known about 370 Macro Assembler. . . .And it is true that to get around in (any) assembly language, you're going to goto and jump, etc. Still, I insist that if you're programming ANY HLL, use structured code. Perform subroutines while, until, do while, use case constructs to simplify otherwise deeply nested if-then-else conditionals. Unfortunately, Perl does not support a true case operation, as does C or JavaScript, et al., but you can fake it. OTTF, Ron W. - Original Message - From: Charles K. Clarkson To: 'Perl Beginners List' Sent: Thursday, January 06, 2005 1:34 AM Subject: RE: Is GOTO evil? Chris Devers [EMAIL PROTECTED] wrote: (RE: Charles K. Clarkson's comment) : In [brief] defense of GOTO, for some programming it is : essential. Assembly language programming, for example. . . Programming in assembler, huh. You're either a computer science student, very curious, or really old. :)
Re: Is GOTO evil?
Don't know if anyone in the discussion has ever written any of IBM's early RPG (note that the options are still in the RPG/400 for the ILE, too, . . .DO NOT USE THEM!), but RPG instructions (known as calculation or C specs. -- nothing to do with the C programming language) have a throw-back conditional feature known as left hand indicators, three of them per instruction, actually, that can be set in a variety of boolean states to determine whether the line of code is to be executed or not. These indicators are boolean switches that can be set on or off (i.e., true or false) elsewhere in the code. As I mentioned, these are throw-backs to the days when the IBM S/3x family of machines was emerging out of the 1410 transistor and 360 mainframe (360 Macro Assembler with JCL, RPG was and the acronym still stands for Report Program Generator,. . .but that's another story). Regardless, a few lines of RPG pseudo-code might look something like this N01 23 N04 DO-Until. . . N24 25 goto somewhere else 45 perform a subroutine 56 if something is equal to something then set indicator 56 off 72 end-if 71 end-do This reads as, If indicator 01 was not set-on somewhere, and if indicator 23 was set-on somewhere, and indicator 04 was not set-on somewhere, then DO something until some condition is met, but oh-by-the-way, while you're in this do-loop, if indicator 24 is not on and indicator 25 is on, then go somewhere else, all the time, keeping in mind that if indicator 24 is turned on, or indicator 25 is turned off, then don't go somewhere, . . .also, if indicator 45 is on, then perform a subroutine while keeping in mind that the performed subroutine could also have similar instructions in it, too); indicator 56 must be on for a conditional if true scenario is to prevent itself from executing again; and as a final aggrevation, that final enddo doesn't count unless indicator 71 is on, similarily indicator 72 conditions the end-if. I'm sure that I've missed some other scenarios, but my point is that this is as EVIL as it gets, or pretzel-logic at it's best? OTTF, Ron W. P.S. In defense of RPG, If's, Do's and While's were not features of RPG-PH (pre-historic) - Original Message - From: Chris Devers To: Charles K. Clarkson Cc: Perl Beginners List Sent: Thursday, January 06, 2005 6:24 AM Subject: RE: Is GOTO evil?
Re: Is GOTO evil?
Chris == Chris Devers [EMAIL PROTECTED] writes: Chris In Perl, the most common legit use of `goto` seems to be jumping out of Chris loops, Really? Where have you even seen that? I can show you an entire decade-spanning career of Perl programming where goto was never used to jump out of a loop. In Perl, we use last, etc. Chris though I wouldn't put it past a clever hacker to do something Chris useful with it in some other context, if s/he knew what they Chris were doing. On the whole though, it seems worth avoiding if it Chris all possible. The goto LABEL in Perl is pessimized. No effort is made to make it work fast. It exists mostly to allow the s2p translator to work. *All* other uses are discouraged. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Is GOTO evil?
Zentara == Zentara [EMAIL PROTECTED] writes: Zentara When you use last to get out of a loop, it only takes you Zentara out of the loop you are in, And this is just wrong. You need to read Learning Perl, because two pages after we introduce last, we talk about labeled loops. Zentara but sometimes you need to go to the end of a block. Yes, labeled loops are the right way to go. Zentara Like in this contrived example. [bad goto example omitted] -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Is GOTO evil?
This thread can't finish without mention of the classic paper at http://www.acm.org/classics/oct95/ . The only times I've used goto in Perl have been the goto sub form, which isn't much of a goto in the first place :-) -- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Is GOTO evil?
On 6 Jan 2005 16:11:40 -, Peter Scott [EMAIL PROTECTED] wrote: The only times I've used goto in Perl have been the goto sub form, which isn't much of a goto in the first place :-) I use it the most when I'm debugging. For example, if I'm hacking on a webpage with a bunch of redirects, I'll stick a label at the very end of the page and goto that so I can print debug info when the page is in a certain state. goto sub is cool too :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Is GOTO evil?
I thought it stood for 'Repugnant Piece of Garbage'.. From: Ron Wingfield [mailto:[EMAIL PROTECTED] Sent: Thursday, January 06, 2005 7:27 AM To: Perl Beginners List; Charles K. Clarkson Cc: Dan Sturgill; [EMAIL PROTECTED]; Kerry Townsend; Burns, Edwin G. Subject: Re: Is GOTO evil? Don't know if anyone in the discussion has ever written any of IBM's early RPG (note that the options are still in the RPG/400 for the ILE, too, . . .DO NOT USE THEM!), but RPG instructions (known as calculation or C specs. -- nothing to do with the C programming language) have a throw-back conditional feature known as left hand indicators, three of them per instruction, actually, that can be set in a variety of boolean states to determine whether the line of code is to be executed or not. These indicators are boolean switches that can be set on or off (i.e., true or false) elsewhere in the code. As I mentioned, these are throw-backs to the days when the IBM S/3x family of machines was emerging out of the 1410 transistor and 360 mainframe (360 Macro Assembler with JCL, RPG was and the acronym still stands for Report Program Generator,. . .but that's another story). Regardless, a few lines of RPG pseudo-code might look something like this N01 23 N04 DO-Until. . . N24 25 goto somewhere else 45 perform a subroutine 56 if something is equal to something then set indicator 56 off 72 end-if 71 end-do This reads as, If indicator 01 was not set-on somewhere, and if indicator 23 was set-on somewhere, and indicator 04 was not set-on somewhere, then DO something until some condition is met, but oh-by-the-way, while you're in this do-loop, if indicator 24 is not on and indicator 25 is on, then go somewhere else, all the time, keeping in mind that if indicator 24 is turned on, or indicator 25 is turned off, then don't go somewhere, . . .also, if indicator 45 is on, then perform a subroutine while keeping in mind that the performed subroutine could also have similar instructions in it, too); indicator 56 must be on for a conditional if true scenario is to prevent itself from executing again; and as a final aggrevation, that final enddo doesn't count unless indicator 71 is on, similarily indicator 72 conditions the end-if. I'm sure that I've missed some other scenarios, but my point is that this is as EVIL as it gets, or pretzel-logic at it's best? OTTF, Ron W. P.S. In defense of RPG, If's, Do's and While's were not features of RPG-PH (pre-historic) - Original Message - From: Chris Devers mailto:[EMAIL PROTECTED] To: Charles K. Clarkson mailto:[EMAIL PROTECTED] Cc: Perl Beginners List mailto:beginners@perl.org Sent: Thursday, January 06, 2005 6:24 AM Subject: RE: Is GOTO evil?
Re: Is GOTO evil?
On Thu, 6 Jan 2005, Randal L. Schwartz wrote: Chris == Chris Devers [EMAIL PROTECTED] writes: Chris In Perl, the most common legit use of `goto` seems to be jumping out of Chris loops, Really? Where have you even seen that? I can show you an entire decade-spanning career of Perl programming where goto was never used to jump out of a loop. In Perl, we use last, etc. Sorry, yes, what he said. What I meant was that the closest construct to a goto that I can think of is using last etc to jump out of a loop. It's not literally goto, but the idea is similar. The goto LABEL in Perl is pessimized. No effort is made to make it work fast. It exists mostly to allow the s2p translator to work. *All* other uses are discouraged. No argument here. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Is GOTO evil?
Christopher Spears [EMAIL PROTECTED] wrote: : I heard a lot of people dislike goto. Why? When : should I use this command? There are three forms of this statement. Each is discussed in the 'perlfunc' reference to 'goto'. Have you read that document? 'goto' is usually used as an advanced tool. It is seldom needed in well designed algorithms. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Is GOTO evil?
On Wed, 5 Jan 2005, Charles K. Clarkson wrote: Christopher Spears [EMAIL PROTECTED] wrote: : I heard a lot of people dislike goto. Why? When : should I use this command? There are three forms of this statement. Each is discussed in the 'perlfunc' reference to 'goto'. Have you read that document? 'goto' is usually used as an advanced tool. It is seldom needed in well designed algorithms. In [brief] defense of GOTO, for some programming it is essential. Assembly language programming, for example. The problem is that if not managed carefully, it can quickly lead to spagetti code: a mash of lines of execution that is nearly impossible to debug. In general, a good rule of thumb is to think carefully about any situation where a GOTO seems like a necessary. In a lot of cases, there will be some clearer way to accomplish the same result -- often in the form of calling a subroutine or jumping out of a loop with a `next FOO` line, or something to that effect. If you think you need it but aren't sure, you can always ask the list for a second opinion :-) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Is GOTO evil?
Chris Devers [EMAIL PROTECTED] wrote: : In [brief] defense of GOTO, for some programming it is : essential. Assembly language programming, for example. Since this is a perl list, we can safely assume the OP was not asking about assembler's goto statement, but about perl's. 'perlfunc' mentions C as a language where goto is more accepted. It also mentions that AUTOLOAD.pm uses the third form to load subroutines. Programming in assembler, huh. You're either a computer science student, very curious, or really old. :) HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response