any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Thu Nov 29 12:25:15 PST 2007


Invariant member functions: you argued these are unnecessary. I believe 
they are, for exactly the same reason as any other invariant references 
passed as parameters. Invariant is needed to support functional 
programming, better code optimization, and more reliable multithreaded code.


const as storage class: Const local variables can be initialized with 
const types, so there is definitely a place for them:

void foo(const int *p)
{
     const q = p;
}

q does *not* point to an invariant.

Furthermore, being able to declare const variables is necessary as they 
are a boundary case in writing generic code. Boundary cases need to be 
supported to make writing generic code easier, even if such code would 
be pointless if done manually. For example, the compiler doesn't 
disallow (0==0), even though it is pointless to write such.



More information about the Digitalmars-d mailing list