Re: Stealing a good idea from Gtk#

On Sep 26, 2004, at 8:00 PM, A. Pagaltzis wrote:

* Torsten Schoenfeld <kaffeetisch gmx de> [2004-09-26 23:45]:
  $button -> Clicked += \&clicked;

i presume you would disconnect a signal with the -= operator?

It's definitely cool. Three things irk me, though:

    a) += just isn't used that way in Perl, and I think
       overloading its meaning the way its done here is too

less politely, it reeks of the operator overloading abuse that commonly afflicts C++/C# people. =)

what irks me the most about it is that, yes it's true that you're adding a handler to the signal, but you're not doing a += operation. a += b makes sense where both a and b are "Foo"s. seen in that light, something like

  <signal> += <handler>

makes less sense. say you wanted to get the id from that connection. you'd now have

  <id> = <signal> += <handler>

which makes even *less* sense. shouldn't the resulting value of Foo+=something still be a Foo?

As far as a) is concerned, the really Perlish way would of course
be a tied array that you can push subrefs onto and delete from...
but ehm, that would be overengineered. :)

(and, actually, impossible. you can find out if there are handlers connected, and you can block and disconnect, but you can't *list* the handlers of a signal on a given instance.)

I'm thinking the operator should be a simple assignment, in which
case you can switch from overload to a tied interface, too.

in defense of the += operator, the += makes sense because you can connect any number of handlers to a signal, while = implies a Highlander nature ("there can be only one!").

how would you handle variants like connect-after and user data? the obvious thing to come to mind is (using Aristotle's naming because StudlyCaps suck)

$window->SIGNAL::delete_event += { handler=>\&my_delete, data =>$thing, after => TRUE }; $window->SIGNAL::delete_event -= { handler=>\&my_delete, data =>$thing };

but by comparison with

  $window->signal_connect_after (delete_event => \&my_delete, $thing);
  $window->signal_handlers_disconnect_by_func (\&my_delete, $thing);

the cool hack way is, well, rather a bit more verbose.

so, i must say i don't like the cool hack, even though it is an impressive and very cool hack.

Brian: If i recall correctly, this is the physics department.
Chris: That explains all that gravity.
        -- Family Guy, "The Story on Page One"

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]