Transitive const sucks

Walter Bright newshound1 at digitalmars.com
Wed Sep 12 00:07:48 PDT 2007


Sean Kelly wrote:
> But for better or worse, D const has a different aim. 
>  The goal is largely to produce a system which allows for compiler 
> optimization rather than to enforce some sort of logical restrictions on 
> behavior.

This is not the primary goal (it is a side effect of the primary goals). 
The goals are:

1) Make functional style programming possible, which will become 
extremely important as people will start using all those lovely cores.

2) Provide compiler enforced semantic guarantees, which improves the 
specification of interfaces between disparate parts of code.

3) Be able to treat invariant references as value types. This, for 
example, makes manipulating strings as easy as manipulating ints.

4) Makes COW programming checkable and enforceable. (COW programming is 
an important part of many styles of programming.) Without transitive 
const, COW is overly reliant on programmer discipline.

> I suspect this means that D apps won't look very much like 
> C++ apps in terms of how const is used, and the overall utility for the 
> average programmer may well be somewhat small.

Yes, it will be used differently. Whether it is overall better or not 
only experience will tell.



More information about the Digitalmars-d mailing list