On 15/01/12 5:57 PM, Robert Jacques wrote:
On Sun, 15 Jan 2012 07:36:53 -0600, Alex Rønne Petersen
Thoughts?

In no particular order:

1) Adding ref to the call site is lexically similar to Hungarian
notation and has all the drawbacks and advantages thereof. I know
invoking Hungarian notation is almost an invocation of Godwin's law when
it comes to programming syntax discussions, but Hungarian notation was
introduced for a reason; there was a time when for large software
projects it dramatically increases code comprehension (and thus quality)
for the code reviewer and/or code maintainer. And that argument still
stand today for anyone _not_ using a modern IDE. The primary reason
Hungarian notation is disparaged today is that IDEs evolved beyond
emacs, vim and notepad. Once they could tell the programmer with a
tooltip what every variable's type was, the need to encode the type in
the variable name vanished. Or more to the original point, modern IDEs
already list function parameter's type and type modifiers (i.e. aka) as
you type the function in so it's _always_ obvious what is ref/const/etc
and what is not. And for the code reviewer, ref parameters could be auto
highlighted/underlined/etc to easy their job. Yes, this issue does need
to be addressed, but I don't think that this is fundamentally a language
problem; it more a lack of modern tools for D. That reminds me, I need
to check out the latest revision of Visual D. :)

A fair point, but:

a) D doesn't have much in terms of *free* highly-featured IDEs.
b) Even if it did, lots of people still use emacs/vim.
c) That does not help when glancing at code to find where a variable is modified.


2) It is perfectly possible to write functions in D that require
explicit demarcation at the call site:

int foo( int* v ) { return *x; }

int y;
int z = foo(@y);

True, but these aren't the same. Pointers can be reseated, ref parameters cannot. Pointers may also be null, encouraging needless null pointer checks.


3) Mandating ref at the call is currently how C# handles reference
parameters. Anytime someone suggests a feature from another language,
particularly C# or Java, two questions are immediately raised in my mind.
3a) Does the asker simply want D to be more like language X?

Perhaps, perhaps not. I think it is better to evaluate a suggestion on its merit and not on the suggester's motivation.


3b) What do programmers experienced in X and in D/C++/C/etc think about
that particular feature (good/bad/ugly)?

Mandated ref is well-received in C# as far as I'm aware.

I also know that people dislike using reference parameters in C++ due to the lack of visibility at the call site (causing them to use pointers).

Reply via email to