Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re^3: RFC: Class::Proxy::MethodChain

by sauoq (Abbot)
on Feb 24, 2003 at 22:15 UTC ( [id://238266]=note: print w/replies, xml ) Need Help??


in reply to Re^3: RFC: Class::Proxy::MethodChain
in thread RFC: Class::Proxy::MethodChain

Look carefully.

That's precisely my point. I'd rather not have to look carefully. Looking carefully should be required by tricky algorithms and obsfucations, not by a series of method calls.

Correct, except for the "some" bit.

I don't see that as a high goal. Typing is easy to begin with, and we can avoid most repetition in it by learning to drive our editors more expertly. Besides, it is much more important that code be easy to read than be easy to write. I agree, of course, that what is easy and what isn't mostly boils down to a matter of personal preference.

I'm not so sure that personal preference alone should govern this case, though. I think this is kludgey at best, and I think I'm being pretty objective about that. You have written a class that does nothing but provide syntactical sugar. It doesn't do so transparently. In some cases it even seems to encourage mixing method calls from two different classes. Also, though unlikely to be a problem in most cases, the code is far from efficient.

My sense of Once And Only Once nearly caused me seizures.

I think this was a false application of that principle. How many times you type a variable name is irrelevant. If you find that your code is performing the same tasks repeatedly, in different places, then the principle applies. In that case, you consolidate the duplicated code and limit the number of pathways thereby reducing the chance for error. Your module actually increases the number of potential pathways through the code. For instance, someone might access a method through your proxy module or directly.

If this is really an attempt to address something that bothers you with Gtk in particular, then maybe you should limit your module to being an auxillary module specifically for use with Gtk. That way, you could get around method name collisions through documentation. The inefficiency issue would probably never matter. And it would encourage the method chaining idiom in the very area you wished to see it. If it really caught on, maybe the Gtk authors would add support for it.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^5: RFC: Class::Proxy::MethodChain
by Aristotle (Chancellor) on Feb 24, 2003 at 23:37 UTC

    I know it wasn't exactly a case of "once and only once", but that's the closest I could get to describe it. What I mean is that I found the previous code hard to read because of all the redundancy. There is a lot of repetition, but no so much that you could scan for patterns; reading the original-style code is downright painful.

    And no, while my immediate concern is Gtk, the thoughts behind this run far further.

    Ah, how I long for the beauty of saying something like

    given(Gtk::FileDialog->new()) { .ok_button.label("Load"); .cancel_button.label("Exit"); .connect_signal(destroy => sub { ... }); # ... }

    :-) That is really what I wanted to get out of this..

    Wait.. I feel an idea coming on.. The problem with the for approach is that you need to weave calls; which is the case because you can't access the topic past the block. If for where an expression that could return something, it would work. One way to get that done would be to abuse map:

    my $window = map { $_->signal_connect(delete => sub { Gtk->exit(0) }); $_->set_title("Test"); $_->border_width(15); $_->add(map { $_->signal_connect(clicked => sub { Gtk->exit(0) }); $_->show; $_ } Gtk::Button->new("Quit"); $_->show; } Gtk::Window->new("toplevel");
    Now I'm not really sure if I should think of this as really clever or really evil.. *grin*

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://238266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found