DMD 1.035 and 2.019 releases

Christopher Wright dhasenan at gmail.com
Thu Sep 4 17:51:22 PDT 2008


Walter Bright wrote:
> bearophile wrote:
>> Walter Bright:
>>> If there's any constructor defined for S, then S(args) is a
>>> constructor call. If there's any opCall defined for S, then S(args)
>>> is an opCall call. Otherwise, it's a struct literal.
>>
>> I haven't tried that in real code, so I can't be sure, but while it
>> may work for the compiler, it sounds a bit too much complex for the
>> person that later reads the code. Too many alternative possibilities
>> may make the code more complex to follow.
>>
>> To reduce such ambiguity (ambiguity for the person, not for the
>> compiler) may be to change the syntax of struct literals...
> 
> I disagree, I think just the reverse. The S(args) syntax means that it's 
> entirely up to the struct designer to say how it should work. The user 
> needn't know or care, and the struct designer can change the design 
> without affecting user code.

This helps a lot with future proofing your structs.

I'm trying to think of a downside...
It's a method call, which is a small performance hit. But it's a very 
small one, considering that it's a final method.

It's a method call, so it could throw an exception. That's just a bug in 
your code, and easier to find than some random error way down the line.

You might be doing something dangerous with leaving stuff on an old 
stack frame and still accessing it. Then you're in the realm of 
undefined behavior.


More information about the Digitalmars-d-announce mailing list