develooper Front page | perl.perl5.porters | Postings from March 2000

teleport ops and useless non-use

Tom Christiansen
March 18, 2000 10:22
teleport ops and useless non-use
Message ID:
These are not flagged with warnings or errors, but
probably should be:

    $x = next JUMP;
    $x = redo JUMP;
    $x = last JUMP;
    $x = goto JUMP;
    $x = dump JUMP;
    $x = die "bad";
    $x = return 42;

(I shall withhold judgment on killing $$. :-)

Beause those are all actions that never return, their 
return values should never be consulted.

This came to me while reading code that said:

    sub compare_numstrs {
        return $a <=> $b or $a cmp $b;

by someone so seduced by the perilously false "C<||> is dead! 
C<or> is better!" hype that they forgot the precedence of "or", 
yet received neither warning nor joy.  Yes, I always tell folks
to use ||, but this doesn't help: "or" still exists, and Pascal
programmers who hold "BEGIN" more legible than "{" have bought
into it hook, line, and stinker, and so hurt themselves with it.

Just as we complain about using proper values in void contexts,
should we not also detect the "opposite" situation?  Is there any
fundamental reason why attempting to use any of the seven teleporting
operators listed above in anything *save* for a void context shouldn't
report this as the nonesense I precieve it to be?  

If not, then I propose that it be classed under the existing "void"
lexical warning class; or, perhaps, that it be placed under a
"nonvoid" class.  But I'd rather avoid proliferation of warning
classes unnecessarily, and this seems a complementary case of the
same problem, so should just get placed amongst the void warnings.

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