For instance, when design a recursion to search a graph it's sometimes desirable to stop immediately after the goal is reached.

I'm having trouble imagining a routine designed to search a graph, where finding the target is a special case?

No need to backtrack and branch thru the whole labyrinth after the exit is already found!

The emotive language makes it sound like returning from (several nested) subroutines is a difficult thing to do; but that is what subroutines do. Via a return or falling off the end. it is neither hard to program nor costly in executions time.

Indeed, whatever alternative mechanism is used, in whatever language, it will always be more costly than the natural return chain. The stack still has to be unwound

Just as the exception mechanism in C++ (or structured exceptions in MSC), are a magnitude or more expensive because they have to search back up the stack looking for stack frames interpreting them as they go; so the goto that underlies such mechanisms in Perl has to go through an equally convoluted process to find a label at the appropriate scope.

Such costs and overheads -- not to mention the difficulties they create when they fail to work as expected and need to be traced and debugged -- are just about acceptable for the exceptional (rare, non-normal) cases they are designed for; but wrapping them over in a cute sounding abstraction and subverting them for use in the general case -- such as a search routine finding what it is looking for -- seems like abuse of the very worse kind to me.

Whilst I'm sure it is possible to contrive a theoretical use case that might stand up to cursory inspection; but unless I saw a real-world use case that I couldn't find a less obscure alternative, any use of the mechanism would garner a big red flag in any code review I was involved in.

Luckily, neither the OP nor you have to subject your code to my review :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Continuations in Perl - Returning to an arbitrary level up the call stack by BrowserUk
in thread Continuations in Perl - Returning to an arbitrary level up the call stack by unlinker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.