Inheritance of purity

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Feb 16 20:10:50 PST 2012


On Thu, Feb 16, 2012 at 07:41:00PM -0800, Walter Bright wrote:
> On 2/16/2012 7:23 PM, Jonathan M Davis wrote:
> >No. Absolutely not. I hate the fact that C++ does this with virtual.
> >It makes it so that you have to constantly look at the base classes
> >to figure out what's virtual and what isn't. It harms maintenance and
> >code understandability. And now you want to do that with @safe, pure,
> >nothrow, and const? Yuck.
> 
> I do not see how it harms maintainability. It does not break any
> existing code. It makes it easier to convert a function hierarchy to
> nothrow, pure, etc.

It's probably the same reason I brought up: looking at a function's
definition will no longer tell you which modifiers are actually in
effect. So you have to trace the overrides up the inheritance hierarchy
in order to know exactly what modifiers it has.

But again, if ddoc can automatically compute this for you, then it
shouldn't be that much of an issue anymore, right?

On that note, though, one thing I've always wanted in a programming
language is to be able to ask the compiler to expand all templates,
deduce all types, etc., for a given function/declaration, and print out
what it actually understands the declaration to be (as opposed to what I
*think* the declaration would expand to). I know that in C/C++ you can
preprocess the source, but it still doesn't expand typedefs, templates,
etc.. Plus the S:N ratio is too low (nobody wants to wade through 5000
lines of preprocessed code just to find that one declaration).

If dmd (and its derivatives) has an option to do this, say perhaps
something like:

	$ dmd -query my.module.myclass.prop01 *.d
	my.module.myclass.prop01:
	my/module.d(123): @property pure lazy const int prop01(int x) { ... }
	$

then this should greatly ease Jonathan's objection to your proposal.
(The current .di files might already sortof fill this purpose, although
.di's have other problems that I don't really want to get into here.)


T

-- 
"I suspect the best way to deal with procrastination is to put off the
procrastination itself until later. I've been meaning to try this, but
haven't gotten around to it yet. " -- swr


More information about the Digitalmars-d mailing list