obsolete D libraries/modules

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Sep 2 08:22:16 PDT 2013


On Mon, Sep 02, 2013 at 04:16:30PM +0200, Andrej Mitrovic wrote:
> On 9/2/13, Jacob Carlborg <doob at me.com> wrote:
> > This is a simple idea:
> >
> > uint timeout;
> > getopt(args, "timeout|t", &timeout).help("Set the timeout");

I don't like having to call getopt multiple times. This is D, we have
delegates, we should only need to traverse args once and do whatever it
is we need to do.


> W.r.t. help strings, I would prefer if we could instead use:
> 
> getopt(args,
>   "timeout|t", &timeout, "Set the timeout",
>   "other", &other,  // note: no comment!
>   "flag|f", &flag, "Set the flag")
> 
> I think we could make getopt support this. For example:
> 
> ["foo", &foo] => name, field
> ["foo", &foo, "foo text"] => name, field, #3 is a comment
> ["foo", &foo, "foo text", "bar", &bar] => #3 is a commen
> ["foo", &foo, "foo text", &bar] => #3 is a new name
> 
> Essentially all getopt has to do is slice up the arguments into
> groups, where an address and the string before it begin a new group.
[...]

I like this idea. I like keeping the option definition, address, and
help text all in one place. When a parse error occurs, getopt can
display the help text for that particular option automatically.


T

-- 
Democracy: The triumph of popularity over principle. -- C.Bond


More information about the Digitalmars-d mailing list