View mode: basic / threaded / horizontal-split · Log in · Help
August 14, 2010
Re: The Status of Const
Graham St Jack Wrote:

> For me, the key problem is that a class object reference has the same 
> const/immutable/shared attribute as the object on the heap that it 
> refers to. This is sometimes what you need, but more often you want a 
> non-shared, mutable reference to a const/immutable/shared object.
> 
> You can achieve this with pointers for arrays, structs and primitive 
> types, but not with classes because a class pointer is just a pointer to 
> a reference.
> 

I discussed a possibility of requiring '*' to denote both references AND pointers before TDPL was out. It would solve a whole bunch of language issues, including this one:

Rebindable!(immutable(Foo)) bar; -> immutable(Foo)* bar;

There is a lot more benefits in the proposal than you might think at first. Here is the link: http://www.digitalmars.com/d/archives/digitalmars/D/What_if_D_would_require_for_reference_types_104816.html

> 
> -- 
> Graham St Jack
>
August 15, 2010
Re: The Status of Const
On 14/08/10 14:39, Denis Koroskin wrote:
> Graham St Jack Wrote:
>
>> For me, the key problem is that a class object reference has the same
>> const/immutable/shared attribute as the object on the heap that it
>> refers to. This is sometimes what you need, but more often you want a
>> non-shared, mutable reference to a const/immutable/shared object.
>>
>> You can achieve this with pointers for arrays, structs and primitive
>> types, but not with classes because a class pointer is just a pointer to
>> a reference.
>>
>
> I discussed a possibility of requiring '*' to denote both references AND pointers before TDPL was out. It would solve a whole bunch of language issues, including this one:
>
> Rebindable!(immutable(Foo)) bar; ->  immutable(Foo)* bar;
>
> There is a lot more benefits in the proposal than you might think at first. Here is the link: http://www.digitalmars.com/d/archives/digitalmars/D/What_if_D_would_require_for_reference_types_104816.html
>
>>
>> --
>> Graham St Jack
>>
>
Thanks for that.

I must admit that the proposal looks really good to me, especially if it 
is compulsory to always use a pointer - i.e. cannot have a class object 
by value. But - for some reason I don't understand, this and the many 
other proposals I have seen don't get up.

Maybe what is needed here is for someone (Walter?) to write up the 
results of the various const/immutable/shared discussions, and put it on 
the website, together with suggested usage idioms. Then we will all 
understand why things are the way they are, and how we should be using 
these language features. This issue has been a running sore for a long 
time, but maybe all it needs is an authoritative write-up to sort it out.


-- 
Graham St Jack
Top | Discussion index | About this forum | D home