in reply to Re: Your named arguments
in thread Your named arguments

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.

Replies are listed 'Best First'.
Re^3: Your named arguments
by dragonchild (Archbishop) on Nov 08, 2005 at 16:54 UTC
    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?