How about "auto" parameters?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jun 7 07:50:22 PDT 2011


On 6/7/11 5:35 AM, Ary Manzana wrote:
> Well, in Ruby every parameter type is auto. And it works pretty well. :-)
>
> When you invoke a method and something goes wrong, like the auto
> parameter doesn't have a method, it gives a sensible error message.

It does, just at run time. The way dynamic languages and static 
languages set up computation is very different and as such difficult to 
compare something as core as function call resolution as equals for equals.

> So:
>
> void foo(auto parameter) {
> return parameter * 2;
> }
>
> could just be the same as
>
> void foo(T)(T parameter) {
> return parameter * 2;
> }
>
> just with a nicer syntax (but I understand it doesn't add much).

The counterpoint is that you seldom want to write foo() as written 
above. You want to clarify what family of types it is intended for.

> I think a reply like: "this is the same as a template" is better than
> "your proposals are of poor quality". It doesn't give a nice look to D,
> specially coming from one of its main leaders.

This criticism is inappropriate, but I'm sure it comes from a confusion 
in reading the thread. I made clear that the proposal you mention is 
sensible (although it has equally sensible counterarguments, which I 
also mentioned). My comment was referring to other proposals following 
an insistence of a poster that it's narrow-mindedness of the community, 
not the quality of his proposals, that renders them rejected.


Andrei


More information about the Digitalmars-d mailing list