Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Surviving 'Illegal division by zero'

by dragonchild (Archbishop)
on Jun 24, 2004 at 12:08 UTC ( #369303=note: print w/replies, xml ) Need Help??


in reply to Re: Surviving 'Illegal division by zero'
in thread Surviving 'Illegal division by zero'

What about the following syntactic sugar?
sub new {my $f; bless \$f => shift; $f -> set(@_) if @_; $f}
That would allow the following modification:
my $fig_1 = MyNumber -> new (get_numeric_value_from_xml (...));

I only propose it because most constructors also allow for values to be passed in, which keeps to the Principle of Least Surprise.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re: Surviving 'Illegal division by zero'
by Abigail-II (Bishop) on Jun 24, 2004 at 12:20 UTC
    I only propose it because most constructors also allow for values to be passed in, which keeps to the Principle of Least Surprise.

    I don't like constructors that are also intializers - constructors that are initializers make MI harder than it should be. I do have some coding guidelines (posted somewhere on this site), and there I explain I don't initialize objects from the constructor for exactly that reason - making MI harder (of course, if your object is anything other than "just a blessed reference", MI is doomed anyway).

    And sure allowing arguments to the constructor, and having the constructor call the initializer if arguments are given works, but it makes the constructor less simple, and hence, less elegant.

    The "everyone else does it" argument doesn't work for me, or else I had used blessed hashrefs for objects instead of just a blessed reference.

    Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2021-09-25 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?