in reply to Re^3: How should named paramater keys be named?
in thread How should named paramater keys be named?
The LWP::UserAgent/WWW::Mechanize API (and especially the WWW::Mechanize::Firefox API) has lots (and lots) of optional parameters, which are mostly filled in as defaults from the object when left out or left alone. The first such example in WWW::Mechanize::Firefox is
$mech->progress_listener( $source, %callbacks )
... where you specify the callbacks by name instead of by position, as usually, you want only to set one or two callbacks.
The same counts for the ->get() method:
$mech->get( $url, %options )
Here, the options can specify a target filename where to store the response, whether to bypass the cache etc.. All of these parameters are fairly orthogonal and it wouldn't make much sense to have them positional in my opinion.
Two APIs that constantly trip me up is the DateTime API and the Imager::Color API. The DateTime API wants me to always specify named parameters when I'm calling any function even though the method only allows one parameter and makes sense for only one parameter. The Imager::Color API raises no warning for:
my $blue = Imager::Color->new( 0, 0, 255 );
... but creates no sensible object either. It wants
my $blue = Imager::Color->new( r => 255, g => 0, b => 0 );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: How should named paramater keys be named?
by BrowserUk (Patriarch) on Jul 02, 2011 at 08:55 UTC | |
Re^5: How should named paramater keys be named?
by tonyc (Friar) on Jul 13, 2011 at 07:48 UTC | |
by Corion (Patriarch) on Jul 13, 2011 at 07:52 UTC |