Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^4: Surviving 'Illegal division by zero'

by ViceRaid (Chaplain)
on Jun 23, 2004 at 22:17 UTC ( #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 from.to_f() end def / (other) other == 0 ? nil : super(other) end end / 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; }


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://369192]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-02-24 20:43 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (363 votes). Check out past polls.