Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

method call overloading: more better tests

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perl.p5p at rjbs

May 16, 2008, 8:30 AM

Post #1 of 6 (177 views)
Permalink
method call overloading: more better tests

I've written one more set of overloaded-method-invocation tests, attached with
a slightly improved version of the classless-root test.

The new tests is a class-based scheme. In my vision of using overloaded
->method, the package-based old-style classes become places to put behavior
about how the "real" class works. They are, in effect, simple metaclasses.
The new test has two of these: Class and Instance. They differ primarily in
their universal methods and in how they dispatch.

I think that these two tests are really exciting! They show that over the
course of a short bus ride, a middling Perl programmer like me can implement
two useful (if woefully trivial) new object systems. Unfortunately, the needed
syntax currently is dreadful. With -> overloading, custom, purpose-optimized
object systems can be made easily, with client code that looks just like good
ol' fashioned Perl.

my $x = $instance->new;
# Fatal: no instance method 'new' on Instance(ParentClass)

my $x = $instance->class->new;
# okay!

It cannot be resisted!

--
rjbs
Attachments: ol-method.tar (20.0 KB)


rgarciasuarez at gmail

May 16, 2008, 8:42 AM

Post #2 of 6 (168 views)
Permalink
Re: method call overloading: more better tests [In reply to]

2008/5/16 Ricardo SIGNES <perl.p5p[at]rjbs.manxome.org>:
>
> I think that these two tests are really exciting! They show that over the
> course of a short bus ride, a middling Perl programmer like me can implement
> two useful (if woefully trivial) new object systems. Unfortunately, the needed
> syntax currently is dreadful. With -> overloading, custom, purpose-optimized
> object systems can be made easily, with client code that looks just like good
> ol' fashioned Perl.

Your way of abstracting out method calls, or whatever, makes my head
hurt. But that looks cool !! now find someone to write the code ! :)


perl.p5p at rjbs

May 16, 2008, 9:38 AM

Post #3 of 6 (168 views)
Permalink
Re: method call overloading: more better tests [In reply to]

* Rafael Garcia-Suarez <rgarciasuarez[at]gmail.com> [2008-05-16T11:42:12]
> 2008/5/16 Ricardo SIGNES <perl.p5p[at]rjbs.manxome.org>:
> >
> > I think that these two tests are really exciting! They show that over the
> > course of a short bus ride, a middling Perl programmer like me can
> > implement two useful (if woefully trivial) new object systems.
> > Unfortunately, the needed syntax currently is dreadful. With ->
> > overloading, custom, purpose-optimized object systems can be made easily,
> > with client code that looks just like good ol' fashioned Perl.
>
> Your way of abstracting out method calls, or whatever, makes my head
> hurt. But that looks cool !! now find someone to write the code ! :)

I needed a way to show that it all worked with the underlying implementation
AND test that the sugar DTRT without needing to rewrite crap over and over, but
yeah. It's also sad that the tests for the sugar hide how sweet it is.

Someone has already said he'd have a look at making tests pass. That would be
sweet!

--
rjbs


davidnicol at gmail

May 16, 2008, 1:19 PM

Post #4 of 6 (162 views)
Permalink
Re: method call overloading: more better tests [In reply to]

On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES
<perl.p5p[at]rjbs.manxome.org> wrote:

> my $x = $instance->new;
> # Fatal: no instance method 'new' on Instance(ParentClass)


what's wrong with good old-fashioned

*{ref($instance).'::new'} = sub { die "new invoked on protected
superclass" }

?


demerphq at gmail

May 16, 2008, 1:22 PM

Post #5 of 6 (163 views)
Permalink
Re: method call overloading: more better tests [In reply to]

2008/5/16 David Nicol <davidnicol[at]gmail.com>:
> On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES
> <perl.p5p[at]rjbs.manxome.org> wrote:
>
>> my $x = $instance->new;
>> # Fatal: no instance method 'new' on Instance(ParentClass)
>
>
> what's wrong with good old-fashioned
>
> *{ref($instance).'::new'} = sub { die "new invoked on protected
> superclass" }
>
> ?

Besides that its ugly and hard to explain to a newbie you mean?

yves


--
perl -Mre=debug -e "/just|another|perl|hacker/"


perl.p5p at rjbs

May 16, 2008, 2:00 PM

Post #6 of 6 (163 views)
Permalink
Re: method call overloading: more better tests [In reply to]

* David Nicol <davidnicol[at]gmail.com> [2008-05-16T16:19:03]
> On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES
> <perl.p5p[at]rjbs.manxome.org> wrote:
>
> > my $x = $instance->new;
> > # Fatal: no instance method 'new' on Instance(ParentClass)
>
>
> what's wrong with good old-fashioned
>
> *{ref($instance).'::new'} = sub { die "new invoked on protected
> superclass" }

Well:

(a) it's ugly, confusing and requires turning off strictures
(b) it means that no new Instances can be created
(c) it doesn't actually do the same thing at all

The sample code shows a way to create classes and instances that look like
normal invocants but use different dispatching rules. The example line I cited
above shows that you could make an instance simply not HAVE a new method.

Your murder of Instance::new would be pointless in the context of the example,
because it could not be called. Outside the context of the example, Instance
would be both the "instance class" and the "class class," meaning that now you
can't construct new Instance objects. If Class were to return objects blessed
into Instance, then you can still call Instance->instance_method, which is back
to FAIL.

So, in answer to your question: everything.

--
rjbs

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.