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:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.