develooper Front page | perl.perl5.porters | Postings from June 2022

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
Dave Mitchell
June 19, 2022 12:23
Re: Pre-RFC: yield true feature
Message ID:
On Fri, Jun 17, 2022 at 08:00:10PM -0400, Ricardo Signes wrote:
> Porters,
> Here's what I think, on the matter of eliminating that pesky magic true value.

And here's what I think.

We should be guided by avoiding, as far as possible, edge/special cases,
a.k.a. the principle of least surprise.

So I propose:

1) that the yield_true feature is strictly lexically scoped. Because
otherwise it's a special case.

99.9% of the time it will be enabled at the top of the src file, so no one
will care much. In the rare case that someone does

        use v5.40;
        ... something relying on 5.40 syntax ...
    ... normal perl ...

then regardless whether their code makes much sense of not, it should do
as expected, and croak with " did not return a true value".

2) that, regardless of whether the require returns via an explicit
'return', or by implicitly falling off the end of the src file, whether
perl does the "croak if false" test is governed purely by whether
'yield_true' was in scope at the last statement executed. I.e. we don't
distinguish between implicit and explicit returns - again, otherwise it's
a special case.

If someone really wants the old behaviour under some circumstances, they
can do either:

    die "I detected a problem while executing" if $bad;

or to more exactly reproduce the old behaviour,

    use v5.40;

    if ($bad) {
        no feature 'yield_true';
        return 0;

A power surge on the Bridge is rapidly and correctly diagnosed as a faulty
capacitor by the highly-trained and competent engineering staff.
    -- Things That Never Happen in "Star Trek" #9

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About