constness for arrays

Don Clugston dac at nospam.com.au
Fri Jul 21 03:43:16 PDT 2006


Andrew Fedoniouk wrote:
> Don, I think that reference counting (MOO COW) has the
> same set of "civil rights" as GC so probably it makes sense
> to look on this from language design perspective in more universal
> fashion. RefCounting of arrays is only one particular thing I mean -
> language shall support this idiom with the same quality as GC.

I agree that something more universal would be better. But there's a 
really interesting feature: when you have GC, you don't need full 
reference counting, because you don't need deterministic destruction. 
You only need a single bit. (I think this is correct, but it needs more 
thought).

> In fact for typical and effective refcounting implementation it is
> enough to have ctors/dtors/assignement in structs.

I don't quite agree with this. I think that arrays in D are 
fundamentally different from arrays in C/C++. In C, they're little more 
than syntactic sugar for pointers, whereas in D, they are more like very 
important, built-in structs. If refcounting were more integral in the 
language, it would need to be available for built-in arrays.

> Having them MOO COW can be implemented easily without
> need of runtime model changes.
> 
> And MOO COW is somehow orthogonal to constness.

Yes, that's the point I was trying to make. I thought it was an 
interesting proposal, but doesn't have much to do with compile-time 
constness, except insofar as it reduces the need for full const.

> Again, I would try to find here more universal solution
> rather than particular array problem.
> 
> I beleive that "smart pointer" as an entity will cover
> MOO COW cases. But D does not have facilities
> now for smart pointers at all.

Walter seems to have vehement opposition to operator =. I wonder if it 
is really necessary. Maybe a single opXXX() function could do the job, 
if the compiler had some extra intelligence. (Much as opCmp does all of 
the >,<, >=, <=. Every op= and copy constructor I've ever seen in C++ 
was  very tedious, I wonder if that design pattern could be factored 
into a single function).



More information about the Digitalmars-d mailing list