Flag proposal

Ary Manzana ary at esperanto.org.ar
Tue Jun 14 00:09:53 PDT 2011


On 6/14/11 1:58 PM, so wrote:
> On Tue, 14 Jun 2011 09:48:14 +0300, Ary Manzana <ary at esperanto.org.ar>
> wrote:
>
>> 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).
>
> Tell me this is not true! :)

:-P

> So ruby don't have named arguments and the community came up with a
> solution which is by the look of it heavily influenced by language
> capabilities. No offense and please no kicking butts but... This is
> madness!!!

Well, in fact I don't know if the community came up with this or if the 
creators came up with this. But I'm sure at some point they agreed on 
this because it's supported on the syntax level.


More information about the Digitalmars-d mailing list