develooper Front page | perl.perl5.porters | Postings from March 2007

Re: [PATCH] Extend functionality of UNIVERSAL::DOES() so it handles additional roles, and works in subroutine form.

Thread Previous | Thread Next
From:
chromatic
Date:
March 12, 2007 02:05
Subject:
Re: [PATCH] Extend functionality of UNIVERSAL::DOES() so it handles additional roles, and works in subroutine form.
Message ID:
200703120205.19914.chromatic@wgz.org
On Monday 12 March 2007 01:29, demerphq wrote:

> > Calling it UNIVERSAL::DOES() -- when DOES() is a method in UNIVERSAL adds
> > to the mess.

> Saying its a method is just trying to force a world view onto perl 5
> that doesnt exist.

$ perldoc UNIVERSAL

NAME
       UNIVERSAL - base class for ALL classes (blessed references)

...

	UNIVERSAL provides the following methods:

What form of object orientation stores functions--not methods--in the 
universal base class?

> I think if that view pervails than UNIVERSAL::DOES in its current form
> should be removed from blead. It doesnt really advance things,

I think you don't understand how it works.

> isnt useful by itself,

Untrue.

> isnt documented that it needs helper subs from a 
> different module

That's true only because it doesn't *need* helper subs from a different 
module.

You seem to have the impression that DOES() is broken because you can't use it 
on non-invocants.

Of *course* you can't use it on non-invocants.  It's a method!  I wrote it for 
objects!  That's its purpose!

You can't call new() or DESTROY() on non-invocants either; are they broken?  
Do they need function forms?  Should there be a UNIVERSAL::DESTROY() that you 
can scatter willy-nilly through your code?

(Acme::UNIVERSAL::new already exists.  I highly recommend it for everyone on 
this list who still has the inkling that calling methods as functions is 
remotely sane.)

> What does it do that isa() doesnt do?

It's overridable by subclasses for things such as Test::MockObject, 
Test::MockObject::Extends, proxy objects, and roles such as in Class::Trait 
to override and to query without causing people to flipping the bozo bit that 
trips when they even consider the possibility that the thought of overriding 
isa() might cross someone's mind.

You know--normal object stuff that people do when they don't get wrapped up in 
the tiny little world of structural typing and polymorphism based solely on 
inheritance.

Why does it fall back on isa()?  First, because inheritance also provides an 
allomorphic relationship.  It's certainly not the only way, but it is one 
way.  Second, because copy and paste is a terrible mechanism of code re-use, 
and isa() is already working, tested, and debugged code.

Why does it not do anything besides isa() by default?  Because, by default, 
the only way to mark an allomorphic relationship in Perl 5 is to note it 
yourself.  UNIVERSAL can't detect that.  No code can.  That's why roles are 
important beyond duck-typing with can().  Sure, maybe you can tell the 
difference between Tree::bark() and Dog::bark(), but good luck solving that 
class of problems in general algorithmically.

Again, I have absolutely *no* objection to adding a new does() or DOES() 
operator or does() function to Scalar::Util or wherever, or whatever name 
makes the most sense--but UNIVERSAL::DOES() is not and should never be a 
function.  It's a method!  That's why it's in UNIVERSAL, so that the DOES() 
method is available to all classes and does something allomorphically 
sensible for all invocants!

If you want UNIVERSAL::DOES() to work on things that aren't valid invocants, 
make them valid invocants instead and solve a host of other problems!  Please 
don't perpetuate yet another semantic and syntactic hack upon the world, lest 
someone have to patch the description of UNIVERSAL to say:

NAME
       UNIVERSAL - base class for ALL classes (blessed references) and 
namespace for a bunch of crap completely unrelated to objects because after 
13 years of object orientation in Perl, we still don't understand it

-- c

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About