D const design rationale

eao197 eao197 at intervale.ru
Sat Jun 23 09:24:07 PDT 2007


On Thu, 21 Jun 2007 10:36:12 +0400, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> http://www.digitalmars.com/d/const.html

While reading this topic (specialy discussion between Sean and Walter)  
I've understood what confusing me in current const/invariant/final design:

Keyword 'const' for value-types means immutability. For example, as I  
think, the following declarations are the same:

const int i = 0;
invariant int j = 0;

because both i and j cannot be changed or reassinged, both i and j must be  
initialized at the compile time. DMD 2.000 even doesn't allow getting  
address of i.

But for reference types and for pointers 'const' means 'constant view' to  
other data. That dualism little confuses me.

My propose is dissable use 'const' keyword for value-type and allow  
'const' only for 'constant view'. Let value-type constant be defined by  
'invariant'.

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list