Postblit bug

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 21 13:25:49 PDT 2014


On Tuesday, October 21, 2014 22:26:26 Dmitry Olshansky via Digitalmars-d 
wrote:
> 21-Oct-2014 05:38, Jonathan M Davis via Digitalmars-d пишет:
> > Yeah. Ref-counting and const do not mix in D. The ref-counting would
> > violate const unless it's in a wrapper object or in a table somewhere.
> > The wrapper fails as soon as it ends up being const (either directly or
> > because it's inside of another object that's been marked const). And
> > having a table somewhere outside the object or any wrapper makes it so
> > that it doesn't work with pure. There are some serious, practical
> > downsides to transitive, physical const like D has.
>
> They pretty much boil down to DO NOT use const everywhere, honestly.

Yeah. Using it everywhere is definitely bad, but the question is then where
you _should_ use it. It's quite useful for avoiding code duplication when
immutable is involved (though templatizing everything fixes that too), and
there are definitely times when the guarantee that something isn't going to
mutated is useful (even if it's only for being able reason about the code
well). So, abandoning const entirely seems like a bad idea, but you have to be
very careful about where you do use it, or you paint yourself into a corner
pretty quickly. pure can do the same thing, but it's nowhere near as bad in
that respect.

- Jonathan M Davis




More information about the Digitalmars-d mailing list