Click here to get back home

strategys other than subroutine and OO?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
strategys other than subroutine and OO? Ela 03-20-2008
Posted by Peter J. Holzer on March 22, 2008, 5:49 am
Please log in for more thread options
>> Just a sort of a semi-tangent question, isn't using next and last with
>> labels (to, say, break out of a parent loop from an inner loop in a set
>> of nested loops) implicitly using `goto` ?
>
> Of course. The principle difference, for me, is that next/last/redo
> always jump to the top (or right out) of a block, so blocks are always
> executed straight through up to the point where you jump out. Even
> though it's logically the same (and operationally very slightly slower),
> I would prefer
>
> begin_stuff();
>
> FOO: {
> do_stuff();
> redo FOO if condition();
> }
>
> end_stuff();
>
> to
>
> begin_stuff();
>
> FOO:
> do_stuff();
> goto FOO if condition();
>
> end_stuff();

In that particular case I'd prefer:

begin_stuff();

do {
        do_stuff();
} while (condition());

end_stuff();

but I agree in general. While it's not "structured programming" in the
strict definition (there is more than one way out of a block) it is
"more structured" than spaghetti code. And personally i find

while (<>) {
        some_code();
        next unless $x;

        more_code();
        next unless $y;

        even_more_code();
        next unless $z;

        if_all_goes_well();
}

more readable than

while (<>) {
        some_code();
        if ($x) {
         more_code();
         if ($y) {
                even_more_code();
                if ($z) {
                 if_all_goes_well();
                }
         }
        }
}


Posted by Abigail on March 20, 2008, 6:21 pm
Please log in for more thread options
_
Frank Seitz (devnull4711@web.de) wrote on VCCCXV September MCMXCIII in
][ RedGrittyBrick wrote:
][ > Abigail wrote:
][ >>
][ >>What Knuth and Dijkstra are saying is that it's not so much the use of
][ >>"goto" that should be avoided, the real horror is unstructured programming.
][ >>But most people only know the title of Dijkstra's paper, and not the
][ >>content [1], let alone know what others have to say about it.
][ >
][ > Guilty as charged. Perhaps I am unlucky in that almost all the examples
][ > of GOTO I have had to wrestle with, have been in examples of "spaghetti
][ > programming". It is certainly possible to write spaghetti code without
][ > using GOTO, but use of GOTO seems to encourage this trend in many
][ > programmers.
][
][ Who the hell uses goto today???


I do. Not often, but there are constructs I use less.


Abigail
--
sub fprint f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))

Posted by John Bokma on March 20, 2008, 2:20 pm
Please log in for more thread options

> In nearly 30 years of programming I have completely avoided use of
> GOTO in a professional context. All I have seen continues to convince
> me that Dijkstra was right on this matter. YMMV.

So you avoid last, next, etc. and returns in the middle of subs as well?
To me those are all forms of GOTO.

--
John

http://johnbokma.com/

Posted by xhoster on March 20, 2008, 2:26 pm
Please log in for more thread options
>
> > In nearly 30 years of programming I have completely avoided use of
> > GOTO in a professional context. All I have seen continues to convince
> > me that Dijkstra was right on this matter. YMMV.
>
> So you avoid last, next, etc. and returns in the middle of subs as well?
> To me those are all forms of GOTO.

Where do you draw the line? All looping and branching are also forms of
GOTO, if that is the way one wants to look at it.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Posted by John Bokma on March 20, 2008, 3:05 pm
Please log in for more thread options
xhoster@gmail.com wrote:

>>
>> > In nearly 30 years of programming I have completely avoided use of
>> > GOTO in a professional context. All I have seen continues to convince
>> > me that Dijkstra was right on this matter. YMMV.
>>
>> So you avoid last, next, etc. and returns in the middle of subs as
well?
>> To me those are all forms of GOTO.
>
> Where do you draw the line?

That's a good summary.

--
John

http://johnbokma.com/

Similar ThreadsPosted
help me pass argument to the subroutine and then return the value from that subroutine to another. October 14, 2006, 1:35 am
A subroutine for gcd July 17, 2006, 9:38 am
subroutine July 20, 2006, 5:36 pm
"Undefined subroutine" November 21, 2004, 8:48 pm
How to tell if a subroutine arg is a constant February 24, 2005, 9:13 am
Subroutine Function March 3, 2005, 5:14 pm
subroutine explanation April 22, 2005, 8:40 am
problam in subroutine? December 5, 2005, 1:40 pm
calling subroutine January 3, 2006, 6:35 pm
subroutine doesn't seem to run after calling it. May 9, 2006, 4:04 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap