const?? When and why? This is ugly!

Burton Radons burton.radons at gmail.com
Thu Mar 5 20:26:09 PST 2009


I don't get it either. Any possible application for const in the form of code correctness went out the window once the invariant virus forced all strings to be invariant whether they were or not; so I still need to use dup to guarantee that data won't change underneath me, but then I need to cast it! It doesn't affect pure at all, because pure can be passed invariants which are just casted - the compiler needs to use rules which are a hell of a lot more binding than anything we can provide it to make these determinations. Now that const is not a storage class, it's actually not possible to declare function variables which should be stored in read-only memory (unless if it's encoded somewhere in the thirty or so combinations you can use), which also damages pure. It's a lot more confusing to deal with const data altogether than it used to be.

When I switched from D 1.0 to 2.0 I tried several times to port some large pieces of code over and ultimately gave up, just as everyone has given up trying to do it in C++. It's a hard task moving code through that kind of change.

I've learned to handle it but I would really like to not be fighting the compiler all the time. Is that what I'm supposed to be doing here, really?



More information about the Digitalmars-d mailing list