The Status of Const

Kagamin spam at here.lot
Thu Aug 12 22:10:20 PDT 2010


Jonathan M Davis Wrote:

> The lack of a mutable qualifier seems like it could be 
> another big problem, but I haven't yet written enough code in D to run into that 
> issue (still I'm sure I'll run into it eventually and be highly annoyed - it's 
> just needed too often in C++ for me not to be happy about it missing in D).

I've run into it - Exception, generating its error message on demand and caching it in const toString. I think, it's no problem no not have mutable qualifier, because I don't want it often. And you can create a function like void cacheValue!(T)(ref const T storage, T value);

> I'm a huge fan of const in C++, and I _really_ want to be able to use it in D 
> (the lack of const in D1 is one of the big reasons that chose to use D2 even 
> when it was new rather than mess with D1),

Same here :)
I think, const can be made to work.

> but the bugs related to it have made 
> it difficult, and I just haven't written very much large stuff in D - and that's 
> where you really need it.

How I'm working on a large project written in C#. C# has only D1 const system. Here I've seen no bugs caused by all data beign mutable. Even with public mutable fields. Usually bugs we have are unimplemented logic, incorrectly implemented logic, exceptions swallowing, undocumented external unmanaged (and buggy) library, that wants nice parameters. And bad design, oh... desing is baaaad.


More information about the Digitalmars-d mailing list