DIP66 - Multiple alias this

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Sep 28 19:41:07 UTC 2020


On Mon, Sep 28, 2020 at 06:56:40PM +0000, mw via Digitalmars-d wrote:
[...]
> It's all about resolve name clashing: `alias` means synonyms; let's
> just borrow from Eiffel, instead of re-invent the wheels: the main
> concepts to solve multiple inheritance are these 5 keywords:
> 
> https://www.eiffel.org/doc/eiffel/Eiffel_programming_language_reserved_words
> 
> `rename`
> `export`
> `undefine`
> `redefine`   -- D's override
> `select`

I don't know Eiffel; could you enlighten me as to how it solves the
following instance of the diamond problem?

	struct Resource {
		this(...) { acquireResource(); }
		~this() { releaseResource(); }
	}

	class A {
		Resource x;
	}

	class B : A {
		...
	}

	class C : A {
		...
	}

	class D : B, C {
		// Should D have one instance of A.x, or two instances
		// of A.x? (Putting aside the question of naming for the
		// time being -- let's pretend we have a way of
		// addressing x somehow in either case.)
	}

I can see some situations for which you want two distinct instances of
A.x (there should be two distinct resources acquired by D), and some
other situations for which you want them to be the same (the same
resource should be shared by B and C).  How does Eiffel cater to both
cases?

Regardless of how Eiffel does it, supporting either case in D is going
to be a mess, because it changes the memory layout of B and C, meaning
you'd have to decide beforehand which solution is desired, even if D
hasn't even been written yet (and the need to implement D hasn't even
come up yet).  The only way I can think of to support both cases without
requiring foretelling the future is to access A's members via a virtual
table, which will basically break a lot of the ABI, introduce another
layer of indirection (with its performance implications), and require
extensive rewriting of D's codegen, etc..  Basically, a HUGE amount of
work to implement it and fix the resulting breakage, all for the
marginal (I'd even say questionable) benefit of being able to use
multiple inheritance.

I honestly doubt this will ever happen in D, even if you set aside the
question of whether this is even a good idea to begin with.


T

-- 
For every argument for something, there is always an equal and opposite argument against it. Debates don't give answers, only wounded or inflated egos.


More information about the Digitalmars-d mailing list