Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369192]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2023-06-03 23:52 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (17 votes). Check out past polls.