October 12, 2007
On Fri, Oct 12, 2007 at 11:42:07AM -0400, novice2 wrote:
>> It would be better to implement using syntax that doesn't conflict with
>> other parts of the grammar.  Perhaps:
>> 
>>    window* w = new_window ("alert box", movable: false);
>> 
>
>or using other language expirence, e.g. oracle pl/sql:
>1 - mixing normal and named params prohibited

Common is to allow positional parameters first, followed by unnamed
parameters.  This is how most languages do it, including python (sort of),
Ada, ocaml, and probably others.  The basic rule is that once you have a
named parameter, none following it can be positional.

>2 - use special token between param's name an dvalue (pl/sql uses name=>value )

The colon is a special token in this case, since it isn't possible in the
existing grammar at this position.  Using an entirely new token might help
make better error messages.

Dave
December 15, 2007
Zola schrieb:
> Hi,
> 
> I'm amazed by some things D does have,
> Except I'm puzzled by this one one gaping hole in D.
> 
> It's something I've been pissed off about C++ for 10 years now: Named parameters to functions.
> 
> window* w = new_window("alert box", movable=false);
> 
> We can almost do this in C++ today with boost.parameter and I hate it so much that I refuse to use it, because the only way to do so is by polluting your namespace.
> 
> I'm really surprised to see that D doesn't have this super important feature.
> It redefines and simplifies a whole world of class design.. for user interfaces especially.
> 
> If D included this, I think it would be the tipping point to really getting me into D, and making a serious library for it.
> 
> Please.
> 
> - Z

I really second this feature request.

I often deal with generating a framework api from a database or such. So often the count of parameter can be high. I would like to have named parameters, so i could copy an example call, an fill in like a form.

doTheAction(
	countOfBananas    => 2,
	errorOnBadQuality => true
);

This makes the code even more readable.

Sure i could do that with comments, but the api might be enhanced or changed. With named arguments, the compiler can help to show the places, where a correction is neccessary.

Named arguments are always useful, if the count and sequence of
arguments is not obvious.
For example VHDL/Verilog are using named arguments a lot.

Since D is a multi paradigm language, not everything is OOP and not every method has less than 4 args.

In my case, where I use a generated API, this would allow better readability and faster development.

Frank





December 15, 2007
Frank Benoit wrote:

> Named arguments are always useful, if the count and sequence of
> arguments is not obvious.
> For example VHDL/Verilog are using named arguments a lot.

Ada also has "named parameter association" (as the Ada community calls it). It is, indeed, a nice feature.

Peter
1 2
Next ›   Last »