develooper Front page | perl.perl5.porters | Postings from September 2018

Re: Fatalizations promised for perl-5.30: what is their status

Thread Previous
From:
Dave Mitchell
Date:
September 25, 2018 18:17
Subject:
Re: Fatalizations promised for perl-5.30: what is their status
Message ID:
20180925181713.GE3102@iabyn.com
On Tue, Sep 25, 2018 at 06:27:43PM +0200, Tomasz Konojacki wrote:
> Code that currently warns: 
> 
> my $foo if 0;
> 
> Code that does not:
> 
> my $foo = 1 if 0;
> my $foo if $maybe_false_maybe_not;
> my $foo = 1 if $maybe_false_maybe_not;
> 
> IMO all of the above should warn because they trigger (in some cases
> only potentially) the same weird behaviour.

I can't remember the full details now, but sometime before 5.10.0,
I tried added warnings for a larger class of 'my' conditionals similar
your suggestions, and it turned up too many false positives in CPAN code,
so was reverted and replaced with the weaker 'my $foo if 0'.
That latter form is usually explicitly exploiting the bug to get a state
variable.

I think the biggest issue was blocks of code that only get executed once,
e.g. because they're in the main body of a module, or in a function which
is intended to only get executed once. For example

    my $use_workaround = 1 if $] < 5.01000;

As long as that sort of code isn't in a loop, nor in a sub called multiple
times, it will work perfectly okay.

Also bear in mind that a vocal subsection of the perl community consider
adding *any* new warnings to perl to be an act of betrayal or something.


Looking further, these are the relevant commits:

commit 7921d0f22732c0609e6c9d21be9aaf6e52f99e6b
Commit:     Dave Mitchell <davem@fdisolutions.com>
CommitDate: Thu Mar 4 21:39:47 2004 +0000

    add deprecation warning for my $x if 0


commit 722969e2558105c9a60bf5758cf8dd5f3eedca60
Commit:     Dave Mitchell <davem@fdisolutions.com>
CommitDate: Thu Mar 4 20:33:44 2004 +0000

    retract 22328 and 22332: deprecation warning for my $x if foo

commit edd7382e985077dac6582d6406b3a16fa5fff0e9
Commit:     Dave Mitchell <davem@fdisolutions.com>
CommitDate: Wed Feb 18 11:14:43 2004 +0000

    Add tests for the C<my $x if foo> deprecation, and change the
    warning text

commit dc9aa44637d2171ba3efbf36c71e8591a7ce05d7
Commit:     Dave Mitchell <davem@fdisolutions.com>
CommitDate: Tue Feb 17 23:30:50 2004 +0000

    add deprecation warning for C<my $x if foo> and C<foo && (my $x)>


-- 
"Foul and greedy Dwarf - you have eaten the last candle."
    -- "Hordes of the Things", BBC Radio.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About