DMD 0.177 release
Bill Baxter
dnewsgroup at billbaxter.com
Sun Dec 10 18:44:41 PST 2006
Kirk McDonald wrote:
> Bill Baxter wrote:
>> There's also the consistency issue, that if construction is done with
>> 'this()' for classes it should be done with 'this()' for structs.
>>
>
> One issue I have with allowing struct constructors is that the existence
> of struct constructors implies the existence of struct destructors. Do
> we really want to go that far? Though "static opCall" doesn't scream
> "constructor," it also doesn't seem to imply the user could define a
> destructor. I submit that "this()" would.
That seems like a non-issue to me. Even if people do take that to mean
you can have a destructor, the compiler will crush any such delusions
the moment you try to compile a struct with ~this in it. The compiler
error message could even be "Structs cannot have destructors, only
classes can". That should be pretty clear.
Structs and classes are different in D. That's a fact, and new users
are going to have to deal with it sooner or later. Should the language
emphasize the similarities or stress the differences? I don't think it
makes a big difference in this case.
What's more important I think is that core operations can be performed
in a way that is clear and unambiguous. No matter how you slice it,
construction is a very common operation, and 'static opCall' does not
offer a clear syntax for construction behavior, nor is it unambiguous in
the sense that it can be used for any purpose the user desires. The
fact that everyone was convinced that it must be inefficient because it
*looks* like it's going to do extra copies is just another side effect
of it using unambiguous constructor-like syntax.
Walter went out of his way to avoid "looking hackish" with regard to
foreach loops. It seems very odd to just accept hackish-looking
constructors for structs.
--bb
More information about the Digitalmars-d-announce
mailing list