digitalmars.D - Re: Transitive const sucks
- Bruce Adams <tortoise_74 ya.blah.hoo.co.ok> Sep 12 2007
Bruno Medeiros Wrote:Sean Kelly wrote:read operations. 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. 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. Sean
I'm don't think that's entirely true. 'invariant' the keyword is indeed made to allow several compiler and program optimizations, but 'const' the keyword is really for enforcing program contracts and restrictions, thus improving safety. I don't even think 'const' the keyword has any use whatsoever for optimization. -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Since you mention contracts, one idea I had for a way out of this morass was to use them for enforcing type constraints like const. e.g. const int* foo; is sort of equivalent to: int* foo; static assert((*foo).const == true); The idea needs a bit of work obviously. Bruce.
Sep 12 2007