in reply to Case-insensitive, dash-optional named parameters for your functions
# Perl 6 :) sub restart_server (Str +$host, Int +$port, Int +$timeout) { ...; } # Call using restart_server host => "...", port => ..., timeout => ...; # or restart_server :host«...», :port(...), :timeout(...);
By just adding a + in front of the variable name you can (actually have to) pass this parameter named.
I noticed, in Perl 5, that you often have only a little small function taking only one parameter:
# Perl 5 sub foo { my $a = shift; ...; }
Later on, you see the need to add a second positional parameter. And maybe your small function won't stop growing and you require a third and fourth parameter, too.
sub foo { my ($a, $b, $c, $d) = @_; ...; }
You think, "I should use named paramaters here", but you (read: I) are probably too lazy to rewrite foo to:
sub foo { my %args = @_; my ($a, $b, $c, $d) = @args{qw( a b c d )}; # Or: my ($a, $b, $c, $d) = @{{@_}}{qw( a b c d )}; ...; }
Instead, you keep your positional argument calling (bad). But in Perl 6, all you'll have to do is to add one small little +, and (of course) you won't have to extract the parameters out of @_ yourself! And you get compile-time checking, too :)
|
|---|