The problem with const proposals

Walter Bright newshound1 at digitalmars.com
Fri Dec 7 12:38:33 PST 2007


In developing D, I've found it very helpful to think in terms of 
"axioms", which are fundamental principles that one can test a design 
against. If any tests fail, then one must change the design, or perhaps 
one discovers that the axioms aren't really axioms at all. It's 
analogous to mathematical axioms. In fact, Andrei pointed out that if we 
adhere to axioms, then we can do mathematical proofs about D, such as 
proof of correctness.

For example, in physics we have the axioms:

1) entropy always increases
2) mass and energy are conserved

so if we have a fellow with a new perpetual motion machine design, we 
automatically know he's a crackpot.

In economics, we have the axiom:

1) There ain't no such thing as a free lunch.

and any economic theory that produces something for nothing is a 
crackpot theory.

So, what are our axioms for const/invariant?

1) Const/invariant are transitive.
2) Any type T can be wrapped inside a struct S, and that S can be made 
to behave as a typedef for type T.
3) The contents of invariant types, once constructed, can never change.
4) The contents of const types, once constructed, can never be changed 
through those const contents.
5) For any type T, we can construct a const(T) or an invariant(T) 
without knowing anything about T.



More information about the Digitalmars-d mailing list