Could const/invariant be optional?

Craig Black cblack at ara.com
Mon Mar 31 07:28:57 PDT 2008


"Neil Vice" <psgdg at swiftdsl.com.au> wrote in message 
news:fsnpjv$p7p$1 at digitalmars.com...
>
> "Craig Black" <cblack at ara.com> wrote in message 
> news:fsjh4h$172o$1 at digitalmars.com...
>>I think most would agree that const is more useful for some programs, but 
>>more of an annoyance for others.  Could the const be disabled by a 
>>compiler option?  If I disabled const when compiling a source file, I 
>>could still rely on libraries that supported const, but I could write code 
>>as if there were no const constraints.
>>
>> -Craig
>
> I just don't see the advantage... as far as I'm aware you're never forced 
> to use const and const parameters to library methods for example shouldn't 
> be an issue as they should be implicitly cast without incident.
>
> Even if you have a const object, say returned from a library method, and 
> require a non-const copy of it you can simply dup, and this seems like a 
> relatively rare-case.
>
> Do you have any specific examples where const is significantly 
> inconvenient and as such worth being able to disable?

No specific examples myself.  It just seems that so many people are upset 
about const, it might make them feel better if they can turn it off.  D's 
const system may very well be "mathematically sound".  But the perception is 
that it overcomplicates things.  I personally am not really that attached to 
this idea.  Just thought it might help. 





More information about the Digitalmars-d mailing list