The Status of Const

Michel Fortin michel.fortin at michelf.com
Thu Aug 12 17:04:39 PDT 2010


On 2010-08-12 18:56:50 -0400, dsimcha <dsimcha at yahoo.com> said:

> It would have probably been better if this was brought to a head 
> sooner, but it's better late than never.  Do others agree that D's 
> const system is difficult to impossible to use properly?

I agree. Rebindable looks like a hack, as do creating immutable objects 
or structs.


> Has anyone successfully used D's const system in a non-trivial setting 
> despite these limitations?

I tried to use immutable objects once, to then find out I'd need to use 
Rebindable everywhere, and not being able to use Rebindable correctly 
(it was buggy) made me abandon the idea. Related bugs:
<http://d.puremagic.com/issues/show_bug.cgi?id=3625>
<http://d.puremagic.com/issues/show_bug.cgi?id=3626>


> If so, was it more trouble than it was worth in hindsight?

At one point, I gave up. I don't use const or immutable except for 
trivial things, such as array of primitive types.


> How can these limitations be worked around and/or fixed?

There need to be a concerted effort to make Phobos more aware of 
not-so-new-anymore features such as const/immutable. Phobos should be 
the test bed for any new feature. Currently, it seems that new features 
got added to the compiler one after another, but they were never really 
tested in a real setting, only in small synthetic test cases. This is 
not how you make a practical language.

Those "new features" I'm talking about includes the most notable D2 
features: const/immutable, shared, @safe, pure, did I miss any? It's 
simple: only once Phobos becomes <new feature>-correct will we be able 
to use <new feature> in our own programs. And this process of improving 
Phobos will reveal lacking areas in the specification/implementation of 
the language that will need to be fixed: I know because I stumbled upon 
a couple of them myself.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list