Time to kill T() as (sometimes) working T.init alias ?

Dan dbdavidson at yahoo.com
Tue Dec 11 06:37:46 PST 2012


On Tuesday, 11 December 2012 at 13:01:44 UTC, Andrei Alexandrescu 
wrote:
> Walter and I discussed that it should be possible to automate 
> the dupIfNeeded() (I call it ensureUnique()) calls like this:
>
> * If a method is const or immutable, leave as is
> * For all other methods, insert a ensureUnique() automatically 
> in the prolog code
>
> For this to work, the state must be private and all primitives 
> must be implemented via methods (as opposed to free functions).
>

This sounds good. But ensureUnique replacing dupIfNeeded really 
does two things - (1) determine if a copy is necessary (i.e. has 
a copy already been done) and (2) actually do the copy when 
necessary. What would it use to do the generic copy and what type 
of copy would it be (1 level deep (e.g. dup all fields of 
typeof(this)) or dup recursively deep)?

I don't think the compiler can choose which of these two is 
desired by the user. This would then call for some form of field 
copy mechanism similar to postblit, likely defined by user.

I think giving the struct designer a simpler way to do COW sounds 
very useful. Would love to read a DIP or notes on it. IMHO there 
are many coding use cases for me where even thinking about COW is 
premature optimization. For instance, when it comes to 
configuring a server at startup I really don't care too much 
about extra data copies.

In reading this news groups I see things like Walter is not a fan 
of postblits and sees no need for them OR static named field 
initialization of structs is up for deprecation. These kind of 
issues give pause. I don't think 100% guarantees are needed - but 
it would be nice if discussions hinting at existing features 
being in or out of the language be addressed quickly and vocally 
by either Walter or you.

Also, it would be nice if you release early and often when it 
comes to your thoughts and ideas on new features, like your 
thoughts on ensureUnique. Or, say, if you and Walter do have a 
potential solution or leaning when it comes to replacing 
postblits with true copy constructors it would be great to hear 
about.

I'm not complaining - here, though. Keep up the good work.

Thanks,
Dan


More information about the Digitalmars-d mailing list