mutable keyword

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 23 04:05:34 PDT 2016


On Monday, May 23, 2016 08:19:52 Jack Applegame via Digitalmars-d-learn wrote:
> On Sunday, 22 May 2016 at 13:08:19 UTC, Jonathan M Davis wrote:
> > Given how const and immutable work in D, having any portion of
> > them be treated as mutable, becomes highly problematic. It
> > could theoretically be done by having to mark such variables
> > with an attribute and mark such types with a similar attribute
> > so that the compiler knows that the type in question is not
> > really following the rules of const or immutable and thus
> > doesn't make any assumptions about it like it would normally,
> > but it risks getting rather complicated, and Walter is most
> > definitely not in favor of such an idea. He is absolutely
> > adamant that const is useless unless it's fully const with no
> > backdoors whatsoever. So, I'd be very surprised if any kind of
> > @mutable were added to the language. Certainly, you'd have to
> > have a very strong technical reason to convince him otherwise,
> > and odds are that he's just going to tell you to not use const,
> > if it's not going to work for the type to be const.
>
> Ha-ha. All this does not prevent immutable class to have mutable
> monitor. Why D so often violates its own rules?

I believe that the monitor predates immutable by a significant margin, and
aside from compiler bugs, usually if there is any violation of rules going
on it has to do with stuff that comes from D1 that wasn't necessarily
adjusted appropriately as the language progressed, though sometimes folks do
get things wrong, and it makes it into the compiler or std lib. But when
that sort of thing happens, we try and fix it. I fully expect that the
monitor mess will be fixed at some point. It just hasn't been high enough on
the todo list for it to be fully sorted out yet. I don't know why you think
that D violates its own rules frequently though. It's not perfect, but it
usually does follow its own rules - and when it doesn't, we fix it (though
not always as quickly as would be ideal).

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list