Front page | perl.perl5.porters |
Postings from June 2012
Re: Allowing named arguments in prototypes
Thread Previous
|
Thread Next
From:
David Mertens
Date:
June 29, 2012 22:55
Subject:
Re: Allowing named arguments in prototypes
Message ID:
CA+4ieYWXYdCK7ptCpqb7C5vZyv7aptwbFoxgXCjGFdJywH9+Cw@mail.gmail.com
Peter -
If you have not yet done so, you must play with Method::Signatures. It is a
breath of fresh air in this department. And it will give you a decent idea
of what's already been tried and worked. Hopefully it will give you some
ideas for how to develop a good specification.
The only gripe I have with Method::Signatures is that if your last argument
is a hash (which I know is slurpy, no problem there), there is no
validation in Medthod::Signatures that there is an even number of
arguments. Furthermore, there is no suppression of the warning that crops
up with an odd number of arguments, either. End result: I have to slurp all
trailing args in an array, check that it has an even number of elements,
manually croak if it doesn't, and then assign to a hash if it has an even
number. Bleh.
But otherwise it's a great interface. It's already worked out most of the
implementation kinks, I suspect. The question you'll have to answer is
this: how do you combine the M::S ideas with prototypes?
David
On Fri, Jun 29, 2012 at 8:03 PM, Peter Martini <petercmartini@gmail.com>wrote:
> On Jun 29, 2012 7:44 PM, "Chip Salzenberg" <chip@topsy.com> wrote:
> >
> > Method::Signatures and Method::Signatures::Simple are both good, and
> > both should be well understood before an "improvement" is proposed.
> > There are more, too, but I only know about these two by experience.
> >
> > Incidentally, prototypes per se are almost never helpful, as most code
> > by plain count is OO and object dispatch ignores prototypes.
> >
>
> I know Moose has a couple of ways to do it, too, but I haven't really used
> them - I don't have the luxury of adding cpan packages to all of the
> environments where my scripts need to run.
>
> For example, if I'm writing a pre/post install script for something on
> linux, I can reasonably assume it'll have perl 5.8, maybe even 10 or
> 12. I can't assume it'll have Moose or Method::Signatures.
>
> That said, if someone doesn't like how a hypothetical builtin named
> parameters work, the current solutions on CPAN won't be broken - and
> frankly, I don't think they would switch anyway.
>
> I am sort of a perl evangelist at $WORK. Explaining subs to programmers,
> I have to convince them that prototypes are nothing like what they would
> expect; and explaining it to admins (who may not have a programming
> background), I can't teach subs without also teaching them about the stack.
>
> I'm not looking for fancy or OO, just aiming for a non-cpan way of moving
> my ($a, $b) = @_ into the header.
>
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
Thread Previous
|
Thread Next