Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Thoughts on "one function, flexible arguments"?

by jcb (Vicar)
on Aug 28, 2019 at 23:33 UTC ( #11105195=note: print w/replies, xml ) Need Help??

in reply to Thoughts on "one function, flexible arguments"?

I believe that this is taking TIMTOWDI a bit too far.

The most common form I have seen is a list of key-value pairs as the argument list. Using a hashref is generally done only in functions that have been retrofitted to accept keyword options where a hashref was previously forbidden in the argument list.

sub my_func { my %params = @_; print "Message received: " . $params->{message}; if ($params->{newline}) { print "\n" } }

Replies are listed 'Best First'.
Re^2: Thoughts on "one function, flexible arguments"?
by hornpipe2 (Sexton) on Sep 01, 2019 at 02:18 UTC
    I did some further research on Perlmonks, and found that there are pros and cons to accepting hashref vs listified hash. For example if you make an error in building your hash: one dies at compile-time, the other at run-time.

    I also went out to MetaCPAN and checked the most popular modules list. Using this (highly unscientific) method I determined that most module authors (LWP::UserAgent, DateTime) have gone with listified hash, instead of hashref. So, that is what I'll stick to as well.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11105195]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-11-30 21:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found