Suggestion: signal/slot mechanism
Kristian
kjkilpi at gmail.com
Sat Sep 2 07:12:13 PDT 2006
On Sat, 02 Sep 2006 14:20:22 +0300, Lutger <lutger.blijdestijn at gmail.com>
wrote:
> Kristian wrote:
>> It would be nice if D had a signal/slot mechanism similiar to Qt:
>> http://doc.trolltech.com/4.1/signalsandslots.html
>> It's an elegant way to handle messages sent between objects. It beats
>> event table declarations used by other GUI libraries IMHO.
>> It would make D a lot more appealing language to write GUI
>> applications. Think of wxWidgets written in D... ;)
[snip]
>
> I agree the signal-slot mechanism is nice, but why must it be supported
> by a compiler? There a lots of good libraries in C++ for this, such as
> sigslots, libsigc++ and boost::signals. It is not necessary to have
> extra preprocessor or language support.
>
> It should be possible to do this in a D library. There already is
> dcouple at dsource, but it is inactive. I have been working on a
> signal-slot module myself, the only thing missing now is automatic
> disconnections of which I am not sure how and if to proceed.
Well, one could ask if it's possible to implement a signal/slot mechanism
by using a library (or by doing it by yourself), then why none of the GUI
libraries I'm familiar with do not use it? (Qt uses preprocessor.)
There are several general reasons for a feature being directly supported:
- If a feature is supported by a language, programmers will use it a lot
more often. Actually it almost certainly guarantees that a feature will be
used.
- Syntax sugar. Being the part of a language, the syntax is consistent
with the rest of the statements. This makes the feature (usually) simplier
and easier to use. At least overall readability is better.
- Compile time errors could be more informative.
- If there is a compiler for a operating system, then the feature is
automatically supported in that system, of course.
- You can rely on the feature being bug free. (You can make that
assumption.)
And of course, the S/S mechanism wouldn't look bad at the feature list of
D. ;)
More information about the Digitalmars-d
mailing list