in reply to Your named arguments

sub convert { my ($o) = @_; return if grep { !exists $o->{$_} } qw( from to thing ); ... }
I fail to see the confusion. So what if I use $o->{from} instead of $from? That's just sugar that has a slight readability edge, but not enough to make my P5 code more convoluted. It's a micro-optimization. The bigger gains are naming at all, <50 line subs, 78char lines, and the like.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Your named arguments
by eric256 (Parson) on Nov 08, 2005 at 04:23 UTC

    Confusion? I can understand why you fail to see it, no one mentioned any confusion. ;)

    BTW That was just a simple example of a wired range function signatures avaiable in p6. See http://dev.perl.org/perl6/doc/design/syn/S06.html for all the new options in signatures includeing optional, required, positional, named, slurpy array, and slurpy hash params.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;
      I've been following the thread with not a little bemusement. I think that some people on the list are conflating optional with "will be everywhere!" Heck, I still look up the arguments for splice(). I fully expect to be looking up the various signature types for at least a year or two, and that's ok.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re^2: Your named arguments
by tilly (Archbishop) on Nov 08, 2005 at 16:22 UTC
    Don't think of it as confusion.

    Think of it as an opportunity to do something like strict.pm for argument parameters. Furthermore it is particularly important here because the two places that need to synchronize (subroutine definition and call) are generally far apart in the text, so it is easy to miss a mismatch.

      I actually had this very discussion with stvn this morning, but with respect to Ruby's signatures. To learn Ruby, I've been porting a Tree module that I just wrote in Perl to Ruby. One of the things I would like to be able to do is:
      def add_child( Hash options is optional, Tree *children ) # Subroutine body here end
      Since I cannot do that, I have to do something like:
      def add_child( *children ) options = children[0].is_a( 'Hash' ) ? children.shift : Hash.new; if children.any? { |node| !node.is_a( 'Tree' ) }: raise ArgumentError "Non-Tree argument found in add_child()" end # Resume regular processing here end
      I'd much rather have the subroutine signature do that for me. Perl6 will have this and I hope Ruby2.0 will, but we'll have to see.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?