Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: chaining method calls

by EvdB (Deacon)
on Jun 12, 2003 at 09:22 UTC ( #265307=note: print w/replies, xml ) Need Help??

in reply to chaining method calls

I am not a fan.

Consider this code:

use HugeObject; my $result = 0; { my $object = HugeObject->new(); $result = $object->get_even_bigger(); $object = undef; } # Phew, should free up memory now. if ($result) { # code here }

As the object was created inside the {} it should go out of scope and the memory should be cleared - a good thing. However as object returns a reference to itself it is not cleared, and stays in memory.

If the object had just returned true or false this would not be a problem.

This may not be a problem if you read the docs for HugeObject but why add the compication for some slightly shorter code?

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re^2: chaining method calls
by adrianh (Chancellor) on Jun 12, 2003 at 10:16 UTC

    If it's a method that is intended to return a boolean result then I would return a boolean. I only use chaining on methods that don't return a result.

    If a false result is intended to indicate an error, I would throw an exception instead - so I wouldn't need to store $result.

    For the style of code I write this problem wouldn't be an issue.

    (also, the $object=undef is redundant. It would be collected at the end of scope regardless.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://265307]
Corion idly wonders about creating a series of HTTP requests. There seems to be no framework to generate a series of HTTP requests, like "try all these requests"
[Corion]: This is vaguely inspired by that list of "nasty" strings, which I'd like to replace among HTTP parameters, just to see whether the application crashes, but also for easy downloading of a list of URLs etc
[Corion]: Maybe I'll just conoct something using Algorithm::Permute to create an (OO) generator for such requests, or a simple function.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-01-16 15:36 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (151 votes). Check out past polls.