digitalmars.D - trait for (ddoc)-comments
- David (5/5) Aug 19 2012 I want to get the (ddoc)-comment of a certain function/member/struct …...
- bearophile (4/10) Aug 19 2012 +1 Yeah! :-)
- bearophile (8/11) Aug 19 2012 I am sure there are MANY other possible applications for such a
- David (2/12) Aug 19 2012 Actually, that's why I want that trait :)
- bearophile (9/10) Aug 19 2012 But in practice, as your command line programs get a little more
- David (25/34) Aug 19 2012 I am not writing an actual argparsing-library, I thought of starting
- Dmitry Olshansky (5/43) Aug 19 2012 What's wrong with std.getopt? I thought there was some movement to
- David (1/3) Aug 19 2012 It uses std.getopt for parsing.
- Marco Leise (8/22) Aug 19 2012 Jesus! Did Nick write docopt? It's full of swear words. Hmm,
- David (2/7) Aug 20 2012 So no official word to it?
- bearophile (7/8) Aug 20 2012 Why don't you write here a list of possible applications (use
- Chris Cain (7/9) Aug 20 2012 Although I like the idea and wouldn't mind seeing something like
- Adam D. Ruppe (13/18) Aug 20 2012 http://dlang.org/ddoc.html
- Chris Cain (5/7) Aug 20 2012 That's a good point ... I've never messed with ddoc before, so I
- Andrei Alexandrescu (10/16) Aug 20 2012 Well it should be said there's no commitment, express or implied, from
- bearophile (4/6) Aug 20 2012 Of course. Thank you for your answer.
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (32/37) Aug 20 2012 I implemented this somewhat trivially, so you can do:
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.
Aug 19 2012
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
Aug 19 2012
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
Aug 19 2012
Am 19.08.2012 15:30, schrieb bearophile:David:Actually, that's why I want that trait :)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
Aug 19 2012
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
Aug 19 2012
Am 19.08.2012 16:36, schrieb bearophile:David: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 ...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
Aug 19 2012
On 19-Aug-12 18:45, David wrote:Am 19.08.2012 16:36, schrieb bearophile:What's wrong with std.getopt? I thought there was some movement to improve it (including auto-generating usage messages). -- Olshansky DmitryDavid: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 ...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
Aug 19 2012
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.
Aug 19 2012
Am Sun, 19 Aug 2012 15:30:33 +0200 schrieb "bearophile" <bearophileHUGS lycos.com>:David: =20Jesus! 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. --=20 MarcoI want to get the (ddoc)-comment of a certain=20 function/member/struct =E2=80=A6 so I can generate help-messages at=20 compiletime, without the need to duplicate the comments.=20 I am sure there are MANY other possible applications for such a=20 trait. Compile-time doctests maybe are a bit too much (but they=20 are OK for compile-time functions!), but things like this become=20 possible: http://pypi.python.org/pypi/docopt/0.1 =20 Bye, bearophile
Aug 19 2012
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?
Aug 20 2012
David:So no official word to it?Why don't you write here a list of possible applications (use cases) of your idea? I hope Andrei will comment a little. It's a very simple additive change, and it looks useful. Bye, bearophile
Aug 20 2012
On Monday, 20 August 2012 at 22:41:33 UTC, bearophile wrote:I hope Andrei will comment a little. It's a very simple additive change, and it looks useful.Although I like the idea and wouldn't mind seeing something like this implemented, I disagree that it's a very simple change. It would require that there be some sort of standard for associating comments with their respective methods/structs/classes. See nimrod's [1] way: the comments are actually part of the AST. [1]: http://nimrod-code.org/manual.html#comments
Aug 20 2012
On Monday, 20 August 2012 at 23:18:28 UTC, Chris Cain wrote:Although I like the idea and wouldn't mind seeing something like this implemented, I disagree that it's a very simple change. It would require that there be some sort of standard for associating comments with their respective methods/structs/classes.http://dlang.org/ddoc.html dmd -D generates some html output based on comments. If you do dmd -X -D, the json output includes the comment with the other data, but if you don't use -D, the comment isn't included. dmd must figure if you aren't generating documentation, it can just discard all doc comments. We'd probably want to change that if doing comment as a trait, because it would be mysterious if it didn't work sometimes. BTW I wanted a traits(comment) over the weekend myself. I was asked to generate some metadata for one of my app apis in XML format and send it up to a third party service. I ended up just adding the needed docs by hand.
Aug 20 2012
On Monday, 20 August 2012 at 23:28:54 UTC, Adam D. Ruppe wrote:http://dlang.org/ddoc.html dmd -D generates some html output based on comments.That's a good point ... I've never messed with ddoc before, so I thought it was a different tool... but if all of that information is part of the D spec already, it probably would be a fairly simple addition.
Aug 20 2012
On 8/20/12 6:41 PM, bearophile wrote:David:Well it should be said there's no commitment, express or implied, from anyone's part to make timely comments. Also, simplicity of implementation (alleged or real) has a low priority when it comes to ranking. That being said, just like the next guy I can cautiously say "this seems nice" upon a cursory look. But there are - even when restricting ourselves to ddoc - features of greater importance, such as adding unittests automatically to ddoc. AndreiSo no official word to it?Why don't you write here a list of possible applications (use cases) of your idea? I hope Andrei will comment a little. It's a very simple additive change, and it looks useful.
Aug 20 2012
Andrei Alexandrescu:Well it should be said there's no commitment, express or implied, from anyone's part to make timely comments.Of course. Thank you for your answer. Bye, bearophile
Aug 20 2012
On 19-08-2012 14:26, David wrote: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.I implemented this somewhat trivially, so you can do: /** * Magic. */ void foo() {} pragma(msg, __traits(getDdoc, foo)); But one problem that quickly ruins the usefulness of this is that Ddoc comments are only gathered when -D is passed to DMD (and therefore D_Ddoc is defined). One way to solve this problem is to always gather doc comments unconditionally. This is not optimal, however, because a lot of code is written with the assumption that doc comments should only be present when D_Ddoc is defined, so in many libraries you'll see code that goes like: version (D_Ddoc) { /** * Magic. */ void foo(); } else { void foo() { } } So, I don't know. It seems like a mess to get working properly. -- Alex Rønne Petersen alex lycus.org http://lycus.org
Aug 20 2012