1. You get the tag name visually distinct from its attributes...You do? Just because the second token after the tag name is now a [? IMO, you get far better visual distinction by using whitespace. For instance:
$nest->nest('newlevel', attr1 => 1, attr2 => 2, attr3 => 3);
2. Your API clearly separates arguments that are separateBy that argument, we ought to write
printf "%d", [3.4];
3. Passing an array reference is more efficient than pass by value? Help me out here..That depends. Certainly, pushing one reference on the stack is cheaper that pushing 96 key value pairs. But if you first have to create an array with those 96 key value pairs for the sole purpose of handing the sub a reference which is then has to dereference, all the gain is lost. Unless you know more about the calling code, you cannot say much about the overall gain or loss when using arrayrefs.
4. Easier to extend.Maybe. Does a possible future extension outweight the negatives of code that now needs to change?
Note that by sacrificing point 4 you can get points 1, 2, 3 while remaining backwards compatible by doing something like:
Instead of forcing your ideas of API clearity and visual distinction of the tag name upon the users of your code, you leave it to the users to decide whether they find this important or not.sub nest { my $tagname = $_[0]; my $attributes = @_ == 2 ? $_[1] : [@_[1 .. $#_]]; ... }
In reply to Re: API design - if you're expecting a scalar and an array ....
by JavaFan
in thread API design - if you're expecting a scalar and an array ....
by metaperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |