in reply to "Useless use of a constant" in grep block?

Would it be reasonable for me to expect perl, in the first case, to emit a warning. Say something like "Probably useless use of a constant in grep block"?

Sure its reasonable, but then lots of things are reasonable :)

How often would you make this error? How often would you not notice that @ary didn't get filtered? Average programmer?

I think

rarely * rarely * rarely = warning unimportant

Also, "Probably" doesn't really belong in warnings :) it means this shouldn't be a warning

  • Comment on Re: "Useless use of a constant" in grep block?

Replies are listed 'Best First'.
Re^2: "Useless use of a constant" in grep block?
by perlancar (Hermit) on Jul 31, 2017 at 10:29 UTC

    I tend to agree on the relatively low frequency that people might make this kind of mistake. But:

    Also, "Probably" doesn't really belong in warnings :) it means this shouldn't be a warning

    I beg to differ. Perl has quite a few warnings of this very nature, where a syntax is perfectly valid but probably not what the programmer meant. Some examples (see perldiag for more details and a more complete list):

           Possible attempt to put comments in qw() list
           Possible attempt to separate words with commas
           Possible memory corruption: %s overflowed 3rd argument
           Possible precedence issue with control flow operator
           Possible precedence problem on bitwise %s operator
           Possible unintended interpolation of $\ in regex
           /%s/ should probably be written as "%s"
    
    

      I beg to differ. Perl has quite a few warnings of this very nature, where a syntax is perfectly valid but probably not what the programmer meant. Some examples (see perldiag for more details and a more complete list):

      So sorry but you're wrong :)

      Just cause perl has some that use "probably" doesn't mean they belong in there, cause it doesn't :D they're humans just like me

      Specifically this doesn't belong but its super super old

      Possible attempt to put comments in qw() list Possible attempt to separate words with commas

      I'm sure the larry or whomever could come up with the reason for including it, but I think its stupid cause how can you be surprised when you type that stuff up and then @foo ends up contains both "#" and "," ?

      First time you run the program you discover , hey, qw works exactly as advertised, who knew the manual doesn't lie but no , instead you get annoying warning, cause some tiny percent of learners (0.0000001%) don't know basic debugging (verify the contents of your variables).

      This has annoyed me since I first learned perl. warnings.pm is for work not 5th grade programming class .


      This one should be phrased better than Possible memory corruption: %s overflowed 3rd argument but whats done is done

      I think this is better memory overflow: %s overflowed 3rd argument cause if "memory overflow" doesn't tell you "uh-oh" then surely use diagnostics; would explain it may be "possible memory corruption"


      Possible precedence issue with control flow operator should just be a fatal syntax error , cause there ain't no reason other than obfuscation to allow this nonsense


      Another wording problem Possible unintended interpolation of %s in string, Should read Cannot interpolate %s in string


      This should be fatal /%s/ should probably be written as "%s" cause obfuscation/japh is the only reason to this nonsense  join m/word/ , 1,2,3,4


      Possible unintended interpolation of $\ in regex should be fatal cause it doesn't warn on ther "metacharacter" global variables

      And my favorite Possible precedence problem on bitwise %s operator should read DAMN SON YOU MUST BE A PRECEDENCE GENIUS TO WRITE %s with bitwise %s operator. THE LARRY SALUTES YOU!!

      warnings is warnings its not extra linty warnings

      But yeah what do i know

        When something is (indeed) a warning, there's always the possibility that the warning is incorrect in that it does not align with what the user means. But this alone does not invalidate the fact said warning is useful. For example, using another warning that has "possibly" in its wording:

        % perl -Mstrict -MFoo -we'$Foo::bar = 1' Name "Foo::bar" used only once: possible typo at -e line 1.

        Does the programmer make a typo or does he really mean setting $Foo::bar? perl can never know for sure, so it just emits a warning instead of an error message. The programmer can disable the warning if he knows that he is doing what he wants. Continuing with another warning which you mentioned:

        our @EXPORT = qw( foo bar baz qux quux );

        and a few months later:

        our @EXPORT = qw( foo bar baz qux quux corge grault # not sure we want to export these by default because the name is +rather common, # but let's do it anyways for now thud jet );

        Are you sure that you, even if you're already a veteran, will never make this mistake? perl is being helpful here by emitting a warning. If perl turns out to be wrong here, just disable the warning lexically.

        But I guess there's always the debate of how much should perl offer helping hands and treat the programmer like a novice or stupid person. But hey, humans *are* stupid :)