On 6/14/11 12:32 PM, Nick Sabalausky wrote:
"so"<s...@so.so>  wrote in message news:op.vw1msqy0mpw3zg@so-pc...
On Tue, 14 Jun 2011 04:46:54 +0300, Ary Manzana<a...@esperanto.org.ar>
wrote:

On 6/14/11 8:36 AM, so wrote:
On Mon, 13 Jun 2011 20:19:15 +0300, bearophile<
<bearophileh...@lycos.com>  wrote:

Andrei:

If we all get convinced that named parameters are worth it,

I think this is not going to happen because some people (two?) don't
want this feature.

I think they worth it and it is the right time to talk extensively why
people think they don't.
And reasoning should not be about its failure or success in another
language, we better have our own rules.

IMO named arguments in D at least should do:

- Reordering (since we got default parameters, even better)

- It is enabled only if we have access to the function declaration.

- In a function call we either use named arguments for all the
non-default arguments or call it with the usual syntax. No hybrid stuff,
no confusion.

A different rule can be:
   - Named arguments come last.
   - Any previous arguments match the order.

IMO the main that makes NAs confusing is allowing hybrid calls.
I don't think allowing reordering then introducing two new rules on
ordering is a good idea.

I think Ary's suggestion is very simple and easy to understand. Hybrid calls
are *only* confusing when an unnamed parameter comes after a named one.

Well, that's the way Ruby works :-)

In fact, in Ruby there are no named arguments. So people came up with this idea.

def some_function(param_a, param_b, options = {})
  param_c = options['param_c'] || default_for_c
  param_d = options['param_d'] || default_for_d
end

The last argument is a hash (a dictionary) with a default value of an empty hash.

So you can call it:

some_function(1, 2)
some_function(1, 2, {'param_c' => 3})
some_function(1, 2, {'param_c' => 3, 'param_d' => 4})

But in Ruby there's a rule: you can skip parenthesis. And you can skip the brackets for a hash if it's the last argument. And instead of strings symbols are much nicer and efficient. So...

some_function 1, 2
some_function 1, 2, :param_c => 3
some_function 1, 3, :param_c => 3, :param_d => 4

Of course this won't work in D because passing hashes all the time would be very inneficcient. But I think positional arguments first, named arguments last is a simple rule that's easy to follow and probably implement (maybe when I'll go back to my country I'll try to implement it).

Reply via email to