We can all agree that Perl likes to give lots of rope to its programmers.
Calling UNIVERSAL::isa prevents mocking, but it also prevents nefarious
classes from lying about what they do. Apparently, allowing mocking is *so*
much more useful than safe-guarding against lying that the porters decided
to (1) remove the documentation of this behavior (though anybody who
understands Perl's object system could figure it out) and (2) remove it
from the Exporter list so that it is difficult to bring this function into
your current package.

I rarely find situations to say "never". If you think UNIVERSAL::isa is the
right way to go, then use it. But you really should know what you're
doing---and preventing---before using it this way. Chances are quite good
that the OP had code written by somebody who didn't understand what they
were doing.


On Fri, Aug 29, 2014 at 7:32 AM, David Cantrell <da...@cantrell.org.uk>
wrote:

> On Thu, Aug 28, 2014 at 10:33:15AM -0700, Karen Etheridge wrote:
> > On Thu, Aug 28, 2014 at 12:43:48PM +0100, David Cantrell wrote:
> > > On Wed, Aug 27, 2014 at 08:54:07AM -0700, Karen Etheridge wrote:
> > > > ..but as others have said, you don't 'use UNIVERSAL' directly - in
> fact the
> > > > word 'UNIVERSAL' should never have to appear in your code.
> > > It might never *have to* appear in your code, but it is on occasion
> > > rather handy. UNIVERSAL::isa is useful for non-objecty code that
> > > manipulates or inspects classes, for example.
> > You should never run UNIVERSAL::isa as a function - only run it as a
> > method, using the class or object as the invocation subject.
>
> That wasn't true when chromatic was banging on about this a few years
> back, and it's not true now.
>
> > Calling it this way breaks any code that overrides isa().
>
> You should never override isa().
>
> Look, I can make assertions too!
>
> Overriding isa() is lying, which is naughty.
>
> Look, I can justify my assertions too!
>
> And it's the very fact that SomeClass->isa() might tell lies that means
> that UNIVERSAL::isa() is sometimes the right thing to do.
>
> --
> David Cantrell | Minister for Arbitrary Justice
>
>       You know you're getting old when you fancy the
>       teenager's parent and ignore the teenager
>         -- Paul M in uknot
>



-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

Reply via email to