News for hackers. Stuff that matters.
Re: How I learnt to love Perl by mechanical_fish on Monday December 08, 2008 @01:09AM (#389557)
I agree that sigils are quite nice for readability. But haven't we established that this:

  my ($bar, @baz, %quux) = @_;
while nice and readable, also isn't valid Perl? Because you have to pass references to get both an array and a hash into a Perl subroutine. So doesn't the actual Perl code look something like this? [1]

  my ($bar, $baz, $quux) = @_;
...and then, in the function, you have to remember to say @$baz because $baz is an array reference and %$quux because $quux is a hash reference? And then we have much the same readability problem as PHP, don't we? Except that the PHP programmer has to make fewer guesses, because the language has one fewer fundamental datatype. ;)

(I believe, in my own Perl, I used to work around this issue by using a lot of objects to encapsulate my hashes and arrays.)

Correct me if I'm wrong. I was never the world's most expert Perl programmer, I haven't used the language in several years, and Perl may have improved since I left.

---

[1] Not that there isn't more than one way to do it.

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.