Proper way to handle "alias this" deprecation for classes

H. S. Teoh hsteoh at qfbox.info
Wed May 10 23:16:22 UTC 2023


On Wed, May 10, 2023 at 10:57:13PM +0000, Chris Piker via Digitalmars-d-learn wrote:
> On Wednesday, 10 May 2023 at 20:25:48 UTC, H. S. Teoh wrote:
> > On Wed, May 10, 2023 at 07:56:10PM +0000, Chris Piker via
> > Digitalmars-d-learn wrote: [...]
> > I also suffer from left/right confusion, and always have to pause to
> > think about which is the right(!) word before uttering it.
> Oh, I though was the only one with that difficulty.  Glad to hear I'm
> not alone. :-)

:-)


> I have a tendency to think of things by their purpose when programming
> but not by their location on the line or page.  So terms such as
> "writable" versus "ephemeral" or "addressable" versus "temporary" (or
> "register"), make so much more sense to me.

Yeah TBH I was never a fan of the lvalue/rvalue terminology. In a
hypothetical language where the arguments to an assignment operator is
reversed, the terminology would become needlessly confusing. E.g., if
there was an operator `X => Y;` that means "assign the value of X to Y",
then the roles of lvalues/rvalues would be reversed.


> Back on the ref issue for a moment... I'd imagine that asking the
> compiler to delay creating a writable variable until it finds out that
> a storage location is actually needed by subsequent statements, is a
> tall order. So D chose to introduce programmers to lvalues and rvalues
> head-on, instead of creating a leaky abstraction.

It depends on how you look at it. The very concept of a variable in
memory is actually already an abstraction. Modern compilers may
enregister variables or even completely elide them. Assignments may be
reordered, and the CPU may execute things out-of-order (as long as
semantics are preserved). Intermediate values may not get stored at all,
but get folded into the larger computation and perhaps merged with some
other operation with the resulting compound operation mapped to a single
CPU instruction, etc.. So in that sense the compiler is quite capable of
figuring out what to do...

But what it can't do is read the programmer's mind to deduce the intent
of his code. Exact semantics must be somehow conveyed to the compiler,
and sad to say humans aren't very good at being exact. Often we *think*
we know exactly what the computation is, but in reality we gloss over
low-level details that will make a big difference in the outcome of the
computation in the corner cases. The whole rvalue/lvalue business is
really more a way of conveying to the compiler what exactly must happen,
rather than directly corresponding to any actual feature in the
underlying physical machine.


T

-- 
Computerese Irregular Verb Conjugation: I have preferences.  You have biases.  He/She has prejudices. -- Gene Wirchenko


More information about the Digitalmars-d-learn mailing list