Inheritance of purity
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Feb 16 19:15:45 PST 2012
On Thu, Feb 16, 2012 at 06:49:40PM -0800, Walter Bright wrote:
> So it occurred to me that an overriding function could *inherit* the
> qualifiers from the overridden function. The qualifiers of the
> overriding function would be the "tightest" of its explicit qualifiers
> and its overridden function qualifiers. It turns out that most
> functions are naturally pure, so this greatly eases things and
> eliminates annoying typing.
I like this idea.
> I want do to this for @safe, pure, nothrow, and even const.
> I think it is semantically sound, as well. The overriding function
> body will be semantically checked against this tightest set of
> What do you think?
Semantically, it makes sense. And reducing typing is always good.
(That's one of my pet peeves about Java: too much typing just to achieve
something really simple. It feels like being forced to kill a mosquito
with a laser-guided missile by specifying 3D coordinates accurate to 10
The one disadvantage I can think of is that it will no longer be clear
exactly what qualifiers are in effect just by looking at the function
definition in a derived class. Which is not terrible, I suppose, but I
can see how it might get annoying if you have to trace the overrides all
the way up the inheritance hierarchy just to find out what qualifiers a
function actually has.
OTOH, if ddoc could automatically fill in the effective qualifiers, then
this will be a non-problem. ;-)
Frank disagreement binds closer than feigned agreement.
More information about the Digitalmars-d