in reply to Re^2: warnings and strict -- The 2 Best Ways You Can Improve Your Programming
in thread warnings and strict -- The 2 Best Ways You Can Improve Your Programming

Without prototypes, the following two calls are equivalent:
sub ratio_change {...} my @args = ($start_value, $start_total, $new_value, $new_total); ratio_change @args; # Same result as: ratio_change $start_value, $start_total, $new_value, $new_total;
But with prototypes, they aren't:
sub ratio_change ($$$$) {...} my @args = ($start_value, $start_total, $new_value, $new_total); ratio_change @args; # Eeks. Won't do what you think it does. ratio_change $start_value, $start_total, $new_value, $new_total;

I don't shy away totally from using prototypes, but the only types I use are:

sub foo (); sub foo ($); sub foo (&@); sub foo (\@@); sub foo (\%@);
that is, I purely use prototypes to tell the parser how to parse things. I don't use it for argument checking (which is the typical use for '$$$$' style prototypes) as that get annoying fast - due to '$''s side effect of creating scalar context.
Perl --((8:>*

Replies are listed 'Best First'.
Re^4: warnings and strict -- The 2 Best Ways You Can Improve Your Programming
by liverpole (Monsignor) on Oct 05, 2005 at 14:06 UTC
    I hadn't considered that argument, but it makes a lot of sense.  I can see where passing @list would now be prohibited because of a narrowing of definition of what passed parameters are legal.

    Since I still prefer to put subroutines at the end of the file, and call them with the simpler my $result = function $a, $b, $c; (or my $result = function @abc_list;), I will try to stick to using prototypes like:  sub ratio_change; where the argument list (and parens) are unspecified.

      There's no prototype in:
      sub ration_change;
      That's a (forward) declaration. If you use a prototype, both the declaration, and the definition of the subroutine should have prototypes, and the prototypes should be identical.
      Perl --((8:>*
        You're right ... I stand corrected. ;-)