Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Perl Best Practices - Loop Labels

by Anonymous Monk
on Apr 16, 2020 at 20:07 UTC ( #11115648=note: print w/replies, xml ) Need Help??

in reply to Perl Best Practices - Loop Labels

To me, "loop labels are GOTOs." They represent too-easily-overlooked logic, lurking deep within the depths of the nest of loops, which is "extremely, yet deviously" concerned with how the loop-structure will actually behave. You can be innocently looking at a nice piece of source-code that appears to represent "nested loops," and have utterly no idea that some other piece of code, somewhere you'd never have thought of, might contain a last statement that "might or might not(!)" be executed. (Perl is a totally dynamic language: "nothing is truly structural, everything executes.")

"Best practice?" Stomp them out!

Replies are listed 'Best First'.
Re^2: Perl Best Practices - Loop Labels
by Your Mother (Bishop) on Apr 16, 2020 at 20:17 UTC

    Maybe you could show some code demonstrating your point or clarify this, nothing is truly structural, everything executes, or show something, anything, worth reading. I am personally in accord with some of the best programmers at the monastery who already answered: loop labels can be nice, elucidating even, as long as they are only a couple—three would be my limit before biting the refactoring bullet—deep.

Re^2: Perl Best Practices - Loop Labels
by haukex (Bishop) on Apr 16, 2020 at 20:43 UTC
    To me, "loop labels are GOTOs." ... "Best practice?" Stomp them out!

    I realize I'm responding to a troll, but this is just way too wrong. Yes, one can write bad code in any language. But labels applied to loops and blocks are the solution to avoid gotos. Just one example, compare the code in this node to the one in my reply.

Re^2: Perl Best Practices - Loop Labels
by BillKSmith (Prior) on Apr 17, 2020 at 03:32 UTC
    If you find the deeply nested 'if blocks' usually needed to replace 'next' or 'last' are easier to maintain, use them - always! Personally, I strongly prefer 'next' and 'last'. The issue of labels is much less clear.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11115648]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2020-09-23 14:13 GMT
Find Nodes?
    Voting Booth?
    If at first I don’t succeed, I …

    Results (131 votes). Check out past polls.