Is the address-of operator (&) really needed?
foobar
foo at bar.com
Sat Jun 2 07:02:00 PDT 2012
On Friday, 1 June 2012 at 17:07:57 UTC, Sandeep Datta wrote:
>> 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.
Wrong. Preferring #1 over #2 completely ignores real life usage.
What actually happens is that we read code more often than
writing it (orders of magnitude more) and we also read other
people's code as well. Obviouisly we only write our own code.
This raises nightmares of my time as a junior developer
maintaining code written by some morrons that decided to name
functions with 4-letter abbreviations without any form of
documentation what so ever. While I'm sure the original code was
very clever and made perfect sense to those original developers
and those abreviations were trivially obvious to them, it
certainly has no meaning whatsoever to a new guy 30 years later.
So no, prefering ease of writing over ease of reading is a STUPID
MORONIC WRONG idea. In fact, all those fancy modern tools such as
IDEs help write more readable code by auto-completeing long
function names, aleviating the need to used criptic abreviations
for faster writing sake.
/rant
Regarding the specific issue of the & - I think that it's a
little more consistent to not have it but given the technical
issues raised by others it ain't worth it at this time.
More information about the Digitalmars-d
mailing list