Named parameters

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 28 21:37:10 PDT 2015


On Sat, 25 Jul 2015 23:05:38 +0000, Jonathan M Davis wrote:

>> Well, somebody was insisting and my PR's wouldn't get pulled without
>> converting to it. Bluntly, I think insisting on using Flag instead of
>> bool is not worth the bother.
> 
> Several of those with commit access seem to have taken a liking to it
> and insist that it's best practice, and I'm not enthused about it
> either. Maybe some of those same devs would like to have named arguments
> as well. I don't know.

semi-OT: as D has no named args, and i want to stay compatible, i adopted 
some another bad style:

  myfunc!"use-x,do-y,skip-z"(...);

i.e. using template with string arg and parse that arg in compile time. 
while this bloats binary, creating separate functions for each option 
set, it still allows me to specify user-readable function configs. small 
example: one of my parsing functions has alot of options (i need 'em to 
correctly parse both xpath and css), and looks like this:

  lex.nextToken!"spacetokens,comments,no-numbers,extids"();

with named args that can be simple:

  lex.nextToken(spacetokens:true,comments:false<,etc...>);

while this can be done with Flag, of course, what named args can give me 
is the ability to pass arguments in any order i like -- compiler knows 
the names and will sort 'em. still nice syntax, no template bloat.

of course, there are other solutions to this, but the only one that 
doesn't require additional code in lexer is named args one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150729/7826aa2f/attachment.sig>


More information about the Digitalmars-d mailing list