Logical const

spir denis.spir at gmail.com
Wed Dec 1 06:17:56 PST 2010


On Wed, 1 Dec 2010 03:22:39 -0800
Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> > What would be the consequences if D had no const, only immutable (that,
> > IIUC, removes the latter non-guarantee)?  
> 
> The biggest problem would be that no function could then work on both a mutable 
> and an immutable value (unless it could be copied by value). With const, you can 
> pass both mutable and immutable stuff to it. Without const, any and all functions 
> which would want to deal with both would have to be duplicated. That includes 
> stuff like member functions.

Right, but isn't this the main point of Unqual!? (Would unqualify immutable as well, no?).

> And of course, as C++ shows, there are plenty of cases where having const but no 
> immutable can be quite valuable. Just the fact that you can pass an object to a 
> function and know with reasonable certainty (and more certainty in D than C++) 
> than that object won't be altered can be extremely valuable. Sure, many 
> languages get by without const, but I think that they're definitely worse off for 
> it. And with immutable added to the mix, I think that const is that much more 
> important.

For this case, I prefere the "in" qualifier. (And imo value parameters should be "in" by default).
Unless I miss important use cases, seems I would be happy with "immutable" and "in".


denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list