Is the address-of operator (&) really needed?

Sandeep Datta datta.sandeep at gmail.com
Fri Jun 1 10:07:55 PDT 2012


> I would add that "fptr = &function;" makes it _clear_ what is 
> going on
> there, otherwise I would have to go and find what "function" 
> is...

There are two contradictory issues at work here which need to be 
balanced with each other...

1. While writing code we expect the compiler to understand what 
we want to do without writing a lot of code. Compiler inference 
is a boon here. D has some features supporting this (like auto).

2. While reading code and while trying to reason about the 
program we want the program to be self documenting and simple. 
Often as is the case with natural languages some redundancy is 
required to accomplish this. This makes a language verbose and 
increases the difficulty / effort required for writing programs.

We don't have many tools which can help us with item #1 but we do 
have tools which can help significantly with item #2 (eg. IDEs, 
static code analyzers etc) so IMHO we should design our languages 
to help us with item #1.

Removing the ampersand is one small step in this direction. 
Though I agree upfront I have not mastered all the nuances of D 
to even know if this is possible at all at this point of time.


More information about the Digitalmars-d mailing list