Requiring weak purity for opAssign, postblit

Tomek Sowiński just at ask.me
Sat Dec 25 10:46:17 PST 2010


dsimcha <dsimcha at yahoo.com> wrote:
> I've been thinking about adding purity to various parts of Phobos and
> one
> thing that limits this in the case of containers is templated
> containers,
> arrays, etc. that may be instantiated with a user-defined type.  In
> theory,
> even assigning/copying a user-defined type could be impure.  Does
> anyone see a
> problem with requiring opAssign and postblits to be weakly pure to
> solve this
> problem?

I guess a postblit could obtain a "new" instance by taking one off a
freelist.

>From bird's eye, the more code I write with the new pure design the more
these two thoughts get reinforced:

1. Technically speaking it's excellent, solves quite a bit.
2. Functions ought to be weakly pure by default (please don't dismiss as
bikeshedding). It's the most common case by a large margin. Plus,
functions that do use globals need more attention from reviewers, so
making *them* greppable saves time.

-- 
Tomek


More information about the Digitalmars-d mailing list