Closed bmartin closed 4 years ago
The motivation for this policy is to restrict or eliminate unused variables. In the case of a subroutine some of whose return values are unused, I believe it would be simpler and clearer to code it thus:
my ( undef, $bb ) = MyFunc();
No need to annotate on your part, no need to maintain extra code on mine.
Yes, that works. Perhaps it makes sense to convert this to a doc request to add an example of using undef?
Will do. I believe it's the usual Perl idiom for things like this, but it's far from obvious.
Normally what I do in this case is figure out a doc change, run it by the requestor, then put out a development release. But I don't have a lot of tuits at the moment. Would you be so good as to rattle my cage in a couple weeks if you don't see or hear anything from me?
Just pushed a commit. What I did was to add a POD section AVOIDING UNUSED VARIABLES. This has one subsection, "List Assignments." You're invited to read and comment. Please read critically, as I have great faith in my own ability to communicate unclearly.
Thank you! That's exactly what I was hoping for.
Thanks for the feedback. Development version 0.107_01 just went to PAUSE, and ultimately to a CPAN mirror near you. I normally give things a week for the CPAN testers to chew on them, and then make a production release.
I find this policy very valuable, but it can be pretty cumbersome in cases of functions that return two arguments like so:
This can occur very common in code and writing a supression each time is awkward
Also, if I know that
$aa
is expected to be unused, I'd still like it to tell me that$bb
is unused.I believe this is nicer because it is very explicit:
I have a sample implementation below. Ideally, it would be symmetric so using
$aa_unused
would become invalid.Possible Solution
To achieve that in my personal fork, I added this to my
.perlcriticrc
:and made these changes to
Perl/Critic/Policy/Variables/ProhibitUnusedVarsStricter.pm