evalEmpire / perl5i

A single module to fix as much of Perl 5 as possible in one go
http://search.cpan.org/perldoc?perl5i
Other
156 stars 42 forks source link

Methods that take options should take hashes not refs #243

Open notbenh opened 11 years ago

notbenh commented 11 years ago
$thing->method(option => 42);

rather then the current goal for v2

$thing->method({option => 42});
schwern commented 11 years ago

We discussed this briefly at the PDX Hackathon. How our methods take options is a bit higgly piggly. The argument for using a normal hash is quite simple, its easier to type and remember. It also happens to jive with how named parameters work in Method::Signatures if we wind up using that.

IIRC I'd originally intended to have methods take a hash ref for two reasons. 1) Its a bit more memory efficient and 2) its easier to distinguish the options from other arguments.

1 doesn't matter for the overwhelming majority of option passing, and if we do need to pass in something large as an option the individual option can be passed in as a scalar.

2 doesn't matter for us because, with autoboxing, we pass in the data as the object. Any auxiliary stuff can come in either as an option or, if its required, as a positional in front of the options. $thing->method( $more_data, option1 => value2, option2 => value2 ); If we need to pass in more data later it must be optional, so it goes with the options.