Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: Surviving 'Illegal division by zero'

by ViceRaid (Chaplain)
on Jun 23, 2004 at 22:17 UTC ( [id://369192]=note: print w/replies, xml ) Need Help??


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

And, this is the way to "directly re-open the method definitions". In fact, it's safer to do it this way than it is to redefine it for the whole program. That kind of "action-at-a-distance" is the source of more maintenance nightmares than anything else.

Totally agree. Before Abigail's post I hadn't really thought of it in OO (obj-oriented and op-overloading) terms. To put what you're saying in, uh, ahem, pseudocode, it's the difference between globally redefining a core method

class Float alias :old_divide :/ def / (other) other == 0 ? nil : old_divide(other) end end

and subclassing, which is all good

class MyFloat < Float def MyFloat.new(from) from.to_f() end def / (other) other == 0 ? nil : super(other) end end MyFloat.new(4) / 0 # nil
A last concept to leave you with - if someone were to take your code and wrap it in something else, which is the politer way to handle things?

Sure, it's a library. I was wondering if there was something scoped lexically analogous to:

use warnings; { no warnings qw/once/; $foo = 5 - $bar; } { no warnings qw/uninitialized/; $foo = 5 - $qux; }

Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-23 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found