Ticket #8 (new enhancement)

Opened 8 months ago

Last modified 2 months ago

Make signal and slots better

Reported by: kaarna Assigned to: JJR
Priority: minor Milestone: Release 2.0
Component: gtkd - classes Version: TRUNK
Keywords: signal slot Cc:

Description

The signals and slots should somehow be made better. I'm no expert on this (I'm no expert on anything...) so it would be nice if someone with some experience with them would show up, and write a suggestion how it should be done.

Current situation is not bad, but it could be better. Currently we have e.g. Button.addOnClicked( void delegate(Button) dlg ) or something like that. It should be made so that it is more flexible. It can't currently accept functions. Only methods (delegates). And only methods that take Button as the only argument. That's not bad, it just isn't flexible. I'd like something like:

void someFunction() { Stdout("Some func.").newline; }

class someClass
{
    void someMethod(){ Stdout("Some method").newline; }
    int evenThisSomehow(int arg) { Stdout("arg was:")(arg).newline; return arg; }
    int returnSomeInterestingValue() { return interestingValue; }
}

Button myButton = new Button("Click me");
myButton.signalClicked.attach(&someFunction);
myButton.signalClicked.attach(&someMethod);
myButton.signalClicked.attach( Signal.bind( &evenThisSomehow, 5 ) );
//And even this:
myButton.signalClicked.attach( Signal.bind( &evenThisSomehow, &returnSomeInterestingValue ) );

//And that would output when clicked:
Some func.
Some method.
arg was: 5
arg was: 29329387 // or what ever interestingValue was at that time...

And then it should also be possible to overload (or is that redefine) the Button.onClicked() method in your own class MyButton? : Button. (And the onClicked method should be attached to the signalClicked slot by default.) And get that to do stuff that you want.

tango.core.Signal could be used for the signals, but that would tie gtkD to Tango. (IMO that's not a bad thing :) but some won't like it. So until Tango is usable with Phobos or they merge in someway, it might be possible to just copy the Signal implementation from Tango and use it with a different name.) They have the limit of not having return types in signals, which I've filed a ticket in Tango.

Just ideas here...

Change History

12/19/07 22:06:10 changed by JJR

I'm a bit biased myself, and would tend to say that we should just look into using the Tango implementation of signal/slots. The problem is that the tango signal/slots is a core module with dependences on other core modules. So this does pose a bit of a problem if we just want to pull that implementation out of tango and into gtkD. It's easier just to use the library itself. As you pointed out, that's not necessarily a popular option.

Overall, I think it's important to note that Tango has loads of functionality for high and low level featuers: excellent threading support (much better than phobos), more reliable garbage collector (fixes bugs in phobos that never got fixed), traced exceptions, logging, active development etc. All these features (and many more) contribute to a strong argument in favour of adopting Tango primarily with Phobos maintained secondarily.

On the hand, Tango still isn't mainstream and poses rather difficult hurdle to newcomer's to D. It still takes some savy to figure out how to get Tango up and running with D(unless one goes directly to the Tango downloads section and downloads the ready made compiler+Tango RC distributions).

Phobos has an advantage over Tango in this regard: it is immediately accessible; most libraries will compile with Phobos as is; and Phobos is relatively static in comparison to Tango's constant development -- meaning minimal requirement to update a project as the core library changes.

These are just some of the disadvantages of adopting a young but extremely versatile library. I don't want to force this choice on people. What I'd like to do instead is add a new gtkD branch that is Tango only (using the signal/slots implementation), and classify it as experimental until both Tango and gtkD mature to a point of consistant reliability. Trunk can remain as is with minimal support for both Tango and Phobos. That's my opinion.

(oh, didn't realize I would right so much under this ticket... guess I got carried away :) )

12/29/07 01:31:32 changed by Pse

  • version set to TRUNK.

07/09/08 06:45:06 changed by okibi

  • milestone changed from Release 1.0 to Release 2.0.