www.digitalmars.com         C & C++   DMDScript  

D - General Questions

reply "Gerald Nunn" <gnunn gexperts.com> writes:
I am very new to D but really like what I see so far, it's apparent the
language design has been extremely well thought out. I do have some
general questions though as follows:

a. Strings in D appear to be referenced counted and copy on write
semantics must be used to prevent references from being corrupted. Was
any thought given to implementing a similar scheme as Delphi's
AnsiString. The AnsiString is also reference counted, however if the
string changes and multiple references are held, a new string is
created and only the reference where the string is being written is
updated to the new string. All other references continue to point to
the old one.

b. Event handling. Java has a disastrous (IMHO) event handling

system based on delegates. Delegation typically requires language
support, is this available in the current version of D?

c. Any idea when reflection will be supported to the point of being
able to meet the needs for an IDE with a drag and drop style visual
builder?

Thanks,

Gerald
Oct 24 2003
next sibling parent reply "Julio César Carrascal Urquijo" <adnoctum phreaker.net> writes:
"Gerald Nunn" <gnunn gexperts.com> wrote in message
news:bnbsjc$2h42$1 digitaldaemon.com...
 I am very new to D but really like what I see so far, it's apparent the
 language design has been extremely well thought out. I do have some
 general questions though as follows:
I'm not a power user of D but since I have been using it for a while I can answer this questions.
 a. Strings in D appear to be referenced counted and copy on write
 semantics must be used to prevent references from being corrupted. Was
 any thought given to implementing a similar scheme as Delphi's
 AnsiString. The AnsiString is also reference counted, however if the
 string changes and multiple references are held, a new string is
 created and only the reference where the string is being written is
 updated to the new string. All other references continue to point to
 the old one.
It works exactly like you describe. Look at the following code: void main() { char[] s1 = "Hello, world!"; char[] s2 = s1, s3 = s1; s1 = "Modified s1"; s2 = "Modified s2"; printf("%.*s\n%.*s\n%.*s\n", s1, s2, s3); } As expected it prints: Modified s1 Modified s2 Hello, world!
 b. Event handling. Java has a disastrous (IMHO) event handling

 system based on delegates. Delegation typically requires language
 support, is this available in the current version of D?
Delegates are supported but they aren't what you think. In D, delegates are like a struct that holds an object reference and a function pointer that can be passed arround and called latter on. Event handling it's not supported by the "core" language but there has ben some discusion of adding support to the standard library throught templates classes. I would be really nice that D added language support for events and event-delegates but the discussed implementation it's good enough for most applications. You can see an example of event handling in DIG and DFBTH libraries (Sorry, don't have the URLs right now).
 c. Any idea when reflection will be supported to the point of being
 able to meet the needs for an IDE with a drag and drop style visual
 builder?
This is really hard to implement in compiled languages like D (not impossible thought). There is some support and you should read both, the language reference and the Wiki, to see the state of the reflection mecanism in D.
 Thanks,

 Gerald
Julio César Carrascal
Oct 24 2003
parent "Julio César Carrascal Urquijo" <adnoctum phreaker.net> writes:
I have been thinking on this for a while and was waiting for a new
discussion on the subject to appear. Since D declarations are compatible
with IDL (The CORBA component description language) the compiler could
generate IDL in binary format (wich is what ORBS transmit over network
connections) for classes and dump that to the .OBJ file.

To reduce code size, the metadata information would not be generated for
every class in a program but for some "marked" classes maybe using a syntax


<Reflection>
class SomeObject
{
    void methodA() {}
    void methodB(int arg1) {}
}

The compiler would add method information to the ClassInfo structure of that
class:

SomeObject o = new SomeObject();

printf("%.*s\n", o.classinfo.name);
foreach (MethodInfo mi; o.classinfo.methods)
{
    printf("Method %.*s:\n", mi.name);
    printf("\tReturns %.*s:\n", mi.returns.name);

    foreach (ArgumentInfo ai; mi.arguments)
        printf("Argument: \t-%.*s:\n", ai.name);
}

And also we'll have the nice side effect that any "marked" class would be a
CORBA component immediatly (I really don't buy the .NET argument that any
class is a component).

I wanted to try ORBIT (the ORB that's used in GNOME) since it's writen in C
and would be easy to interface from D. But that would need some compiler
support to add a pointer to arbitrary information for the ClassInfo
structure.

And there's where my idea got stuck. What do you all think? Is it possible
at all?
Oct 24 2003
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
Gerald Nunn wrote:
 I am very new to D but really like what I see so far, it's apparent the
 language design has been extremely well thought out. I do have some
 general questions though as follows:
The language design has some fairly unavoidable flaws, so i'd say it's okay-ish. :)
 a. Strings in D appear to be referenced counted and copy on write
 semantics must be used to prevent references from being corrupted. Was
 any thought given to implementing a similar scheme as Delphi's
 AnsiString. The AnsiString is also reference counted, however if the
 string changes and multiple references are held, a new string is
 created and only the reference where the string is being written is
 updated to the new string. All other references continue to point to
 the old one.
The D strings are not reference-counted. Nor is anything at all. We use Java-like garbage collection. However, it has to become much more efficient than in Java. We have big plans. :) So, copy-on-write is currently by convention *only*, and thus manual in your code. And since we don't know the usage count for each object at run-time, we cannot enforce COW without major performance penalties. If you have further questions on garbage collection, ask on.
 b. Event handling. Java has a disastrous (IMHO) event handling

 system based on delegates. Delegation typically requires language
 support, is this available in the current version of D?
We have delegates in the language, as well as closures, which do the same trick.
 c. Any idea when reflection will be supported to the point of being
 able to meet the needs for an IDE with a drag and drop style visual
 builder?
For classes, the thing you mean, already is. It is just not documented. BTW, it's not Reflection like in Java, but instead a powerful ClassInfo like in Delphi. You can be sure we have a ton of Delphi fans in the newsgroup.
 Thanks,
You're welcome. -eye
Oct 26 2003