in reply to Re: Re: Re: Re: Is "ref $date eq 'ARRAY'" wrong? What a mess!
in thread Is "ref $date eq 'ARRAY'" wrong?
Ok, I will give you credit that this is a very creative and elegant way to look at and use 'ARRAY', 'HASH', etc. But I think that co-opting the 'ARRAY' name is maybe not so good, for the simple reason that ref($thing) eq 'ARRAY' doesnt work. You have made the same word potentially mean 2 different thing in 2 different contexts. If you want a marker interface like Java, then why not just create one? Then your code can check for that interface explicitly, and you need never confuse your 'ARRAY' with Perl's 'ARRAY'. Also it seems to me that you are using UNIVERSAL (the Perl base class) as a module and not a class. You are mixing your paradigms here.
Yes, you have your encapsulation and parametric polymorphism, but at what cost? IMHO you are violating the principle of least surprise, what I think is a duck, isnt really a duck, you would need to be pretty sure that it quacks exactly like a duck or your well laid plans can come crumbling down. Otherwise you are making assumptions about the internals of the packages/objects you are passing your 'ARRAY' too (basically, what it does with your 'ARRAY') which then violates their encapsulation. This can get really messy when that client package/module is not written/maintained by you.
Yes I know I am anal about my OO, and I know that Perl's OO is a wide open field. But IMHO it could use a little more consitency. TMTOWTDI can still apply even within a more constrained object model.
why do you think UNIVERSAL::isa returning ref type is a bad design (the perl developers obviously don't think so...)?
I actually dont agree with alot of things the Perl developers did. And one of those things is how references are handled. References are currently clunky, and IMHO clearly an afterthought layed upon the original language. Most high-level languages do not force you to deal with things like this, i tend to view it as a sort of high-level memory management, and IMHO a high-level language should insulate you from such things. From what I have read on Perl 6, they are planning to make referencing and dereferencing automatic, but still allow the @{...} syntax to force dereferencing when you need it. But hey, this is just my opion, take it or leave it.
and FWIW, using isa() in this manner is used in quite number of cpan modules.
If quite a number of CPAN modules jumped off the brooklyn bridge, would you? ;-)
But seriously, I respect the elegance of your solution, I just dont agree with it. I myself spent several weeks debating if my class library should add some useful functions to UNIVERSAL, or to package those functions into small classes and use multiple inheritance. In the end, I decided to leave UNIVERSAL as it is, I just couldn't justify what i saw as "changing the language" just for my evil purposes.
-stvn
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: Is "ref $date eq 'ARRAY'" wrong? What a mess!
by d_i_r_t_y (Monk) on Dec 21, 2003 at 16:23 UTC | |
by liz (Monsignor) on Dec 21, 2003 at 16:33 UTC | |
|