3 ms·
What's more readable? Example 1 (my work's internal source filter format): sub function1( CODE $code, ARRAY $arr ) { # body } Example 2 (standard P
by pyre 14y ago
What's more readable?
Example 1 (my work's internal source filter format):
sub function1( CODE $code, ARRAY $arr )
{
# body
}
Example 2 (standard Perl):
sub function1 {
my ($code, $arr) = @_;
die "Bad params." unless ref($code) eq "CODE"
and ref($arr) eq "ARRAY";
# body
}
Example 3 (Method::Signature):
func function1 (Code $code, Array $arr)
{
# body
}
- draegtun 14y agoYes examples 1 & 3 are much better. At some point signatures will be added to core Perl (class/method nearly made it into 5.16 as part of p5-mop proposal. Fingers crossed it will be in 5.18 next year). When not using perl5i or playing with MooseX::Declare I will usually default to Params::Validate so your example would look like this: sub function1 { my ($code, $arr) = validate_pos( @_, {type => CODEREF}, {type => ARRAYREF} ); ... }