View mode: basic / threaded / horizontal-split · Log in · Help
August 19, 2012
trait for (ddoc)-comments
I want to get the (ddoc)-comment of a certain function/member/struct … 
so I can generate help-messages at compiletime, without the need to 
duplicate the comments. Like pythons function.__doc__ or class.__doc__ 
etc. is there anything planed for D, e.g. __traits(getComment, foo.bar)?

If not what do you think of it, I would love this addition.
August 19, 2012
Re: trait for (ddoc)-comments
David:

> I want to get the (ddoc)-comment of a certain 
> function/member/struct … so I can generate help-messages at 
> compiletime, without the need to duplicate the comments. Like 
> pythons function.__doc__ or class.__doc__ etc. is there 
> anything planed for D, e.g. __traits(getComment, foo.bar)?
>
> If not what do you think of it, I would love this addition.

+1 Yeah! :-)

Bye,
bearophile
August 19, 2012
Re: trait for (ddoc)-comments
David:

> I want to get the (ddoc)-comment of a certain 
> function/member/struct … so I can generate help-messages at 
> compiletime, without the need to duplicate the comments.

I am sure there are MANY other possible applications for such a 
trait. Compile-time doctests maybe are a bit too much (but they 
are OK for compile-time functions!), but things like this become 
possible:
http://pypi.python.org/pypi/docopt/0.1

Bye,
bearophile
August 19, 2012
Re: trait for (ddoc)-comments
Am 19.08.2012 15:30, schrieb bearophile:
> David:
>
>> I want to get the (ddoc)-comment of a certain function/member/struct …
>> so I can generate help-messages at compiletime, without the need to
>> duplicate the comments.
>
> I am sure there are MANY other possible applications for such a trait.
> Compile-time doctests maybe are a bit too much (but they are OK for
> compile-time functions!), but things like this become possible:
> http://pypi.python.org/pypi/docopt/0.1
>
> Bye,
> bearophile

Actually, that's why I want that trait :)
August 19, 2012
Re: trait for (ddoc)-comments
David:

> Actually, that's why I want that trait :)

But in practice, as your command line programs get a little more 
complex, docopt is not enough, you need normal programming with 
things like argparse.

So maybe a mix of the two ideas is better, to write most stuff in 
the docstring, and then refine its semantics below with normal 
code.

Bye,
bearophile
August 19, 2012
Re: trait for (ddoc)-comments
Am Sun, 19 Aug 2012 15:30:33 +0200
schrieb "bearophile" <bearophileHUGS@lycos.com>:

> David:
> 
> > I want to get the (ddoc)-comment of a certain 
> > function/member/struct … so I can generate help-messages at 
> > compiletime, without the need to duplicate the comments.
> 
> I am sure there are MANY other possible applications for such a 
> trait. Compile-time doctests maybe are a bit too much (but they 
> are OK for compile-time functions!), but things like this become 
> possible:
> http://pypi.python.org/pypi/docopt/0.1
> 
> Bye,
> bearophile

Jesus! Did Nick write docopt? It's full of swear words. Hmm,
no, Vladimir Keleshev. It sounds nice, I would see the common
Python way of parsing options a big step forward already. E.g.
including help texts and printing the usage info to stdout.

-- 
Marco
August 19, 2012
Re: trait for (ddoc)-comments
Am 19.08.2012 16:36, schrieb bearophile:
> David:
>
>> Actually, that's why I want that trait :)
>
> But in practice, as your command line programs get a little more
> complex, docopt is not enough, you need normal programming with things
> like argparse.
>
> So maybe a mix of the two ideas is better, to write most stuff in the
> docstring, and then refine its semantics below with normal code.
>
> Bye,
> bearophile

I am not writing an actual argparsing-library, I thought of starting 
one, but then I realized, I don't have the time to do something amazing 
like argparse, so I decided to go with a less complex and heavily CTFE'd 
version. It looks like that:

struct AppArguments {
    string username;
    Alias!("username") u;

    string password;
    Alias!("password") p;

    bool credentials;
    Alias!("credentials") c;

    uint width = 1024;
    uint height = 800;

    string host;
    Alias!("host") h;
    ushort port = 25565;

    bool no_snoop = false;
}

void main() {
    auto args = get_options!AppArguments();
}

I added a default --help function to it, if there is no "help" member 
declared in AppArguments, but I realized ... --help without messages is 
kinda pointless ...
August 19, 2012
Re: trait for (ddoc)-comments
On 19-Aug-12 18:45, David wrote:
> Am 19.08.2012 16:36, schrieb bearophile:
>> David:
>>
>>> Actually, that's why I want that trait :)
>>
>> But in practice, as your command line programs get a little more
>> complex, docopt is not enough, you need normal programming with things
>> like argparse.
>>
>> So maybe a mix of the two ideas is better, to write most stuff in the
>> docstring, and then refine its semantics below with normal code.
>>
>> Bye,
>> bearophile
>
> I am not writing an actual argparsing-library, I thought of starting
> one, but then I realized, I don't have the time to do something amazing
> like argparse, so I decided to go with a less complex and heavily CTFE'd
> version. It looks like that:
>
> struct AppArguments {
>      string username;
>      Alias!("username") u;
>
>      string password;
>      Alias!("password") p;
>
>      bool credentials;
>      Alias!("credentials") c;
>
>      uint width = 1024;
>      uint height = 800;
>
>      string host;
>      Alias!("host") h;
>      ushort port = 25565;
>
>      bool no_snoop = false;
> }
>
> void main() {
>      auto args = get_options!AppArguments();
> }
>
> I added a default --help function to it, if there is no "help" member
> declared in AppArguments, but I realized ... --help without messages is
> kinda pointless ...

What's wrong with std.getopt? I thought there was some movement to 
improve it (including auto-generating usage messages).

-- 
Olshansky Dmitry
August 19, 2012
Re: trait for (ddoc)-comments
> What's wrong with std.getopt? I thought there was some movement to
> improve it (including auto-generating usage messages).

It uses std.getopt for parsing.
August 20, 2012
Re: trait for (ddoc)-comments
Am 19.08.2012 14:26, schrieb David:
> I want to get the (ddoc)-comment of a certain function/member/struct …
> so I can generate help-messages at compiletime, without the need to
> duplicate the comments. Like pythons function.__doc__ or class.__doc__
> etc. is there anything planed for D, e.g. __traits(getComment, foo.bar)?
>
> If not what do you think of it, I would love this addition.

So no official word to it?
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home