Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: chaining method calls

by Juerd (Abbot)
on Jun 12, 2003 at 07:02 UTC ( [id://265291]=note: print w/replies, xml ) Need Help??


in reply to chaining method calls

I also find methods that return the object extremely annoying. Of course it is okay to chain method calls, but imNSho, only if the object returned if different from the one used to call the method. That makes sense and is useful, even though that too is not ideal when debugging. I don't mind doing

my $page = LWP::UserAgent->new->request(...)->content;
or
my ($name) = DBIx::Simple ->connect('dbi:SQLite:people') ->query('SELECT name FROM people WHERE email=? LIMIT 1', $email) ->list;
, but I do dislike when a method returns its $_[0].

The argument that I hear the most is that chaining methods like this reduces typing. While that is true, I think it's a very bad reason for actually doing so. Using only globals and no strict is another way to save three characters per first use. Not checking open's return value is another way of typing less. It seems that length reduction and bad style often go together.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: chaining method calls
by adrianh (Chancellor) on Jun 12, 2003 at 09:59 UTC
    The argument that I hear the most is that chaining methods like this reduces typing. While that is true, I think it's a very bad reason for actually doing so. Using only globals and no strict is another way to save three characters per first use. Not checking open's return value is another way of typing less. It seems that length reduction and bad style often go together.

    Using subroutines is a way to save characters. So are foreach loops. You can argue it both ways.

    In many cases I'd agree with Paul Graham that Succinctness is Power.

    I think this is going to be one of those issues that people can agree to disagree over. The idiom has always seemed very natural and clear to me.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-24 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found