Const system names

retard re at tard.com.invalid
Tue Feb 16 07:27:50 PST 2010


Tue, 16 Feb 2010 10:28:28 +0100, Lars T. Kyllingstad wrote:

> bearophile wrote:
>> Alternative names for the transitive const regime of D2, the main
>> difference is that now immutable values are the default:
>> 
>> - "immutable" ==> (nothing, it's the default). - "const" ==> "valview"
>> (a local immutable value view of something). - mutable variable ==>
>> "var"
>> - "enum" ==> "const" (or maybe it can be removed, so it becomes
>> immutable, that is no annotation. The link-time optimization of LDC is
>> able to remove unused values from the binary. Ten years from now all D
>> compilers can be able to do this).
>> 
>> [...]
> 
> I don't agree that immutable should be the the default.  The default
> should be the most common case, which is mutable.

BTW, have you got some numbers from concrete examples such as real world 
programming projects. Note that many variables are not immutable in real 
projects, but they also could be:

Integer boxedIntegerSum(Integer a, Integer b) {
  Integer c = new Integer();
  c.assign(a.getValue() + b.getValue());
  return c;
}

Here you have three immutable variables a, b, and c. In reality they all 
could as well be constant references, a and b also could be immutable 
views:

Integer boxedIntegerSum(immutable Integer a, immutable Integer b) {
  const Integer c = new Integer();
  c.assign(a.getValue() + b.getValue());
  return c;
}



More information about the Digitalmars-d mailing list