News for hackers. Stuff that matters.
Re: How I learnt to love Perl by thwarted on Monday December 08, 2008 @03:39AM (#389666)
This is somewhat of a contrived example. I can't think of any subroutine in perl that I've written, or interfaced with, or seen in production code, that takes multiple types beyond the first argument. If any function is doing that, the function is too complex and should be refactored. What you do see a lot of is stuff of the forms:

   sub foo {
      my($someflag, @subjects) = @_

   sub foo {
      my($self, %options) = @_

   sub foo {
      my($positional, %named) = @_
etc. And in fact, when the way you call these is the 90% case for functions, at least in perl.

   sub dosomething_with_data(@) { ... }
   @data = (1, 2, 3);
   @moredata = (4, 5, 6);
   dosomething_with_data(@data, @moredata);

   sub invoke(%) { ... }
   %common_opts = (a=>1, b=>2);
   invoke(%common_opts, c=>3);
   invoke(%common_opts, c=>6, d=>5);
   %overrides = (b=>3);
   invoke(%common_opts, %overrides, c=>6);
(I included the subroutine prototypes for clarity). In this case, perl is exactly DYIM without the programmer having to think about list folding, array splicing, or hash merging. It just works. This would appear to be true dynamic typing, rather than dynamic typing where I still need to be strict about how I handle the values.

There are no comments on this comment yet.