www.digitalmars.com         C & C++   DMDScript  

D - Request for review: getopt module

reply Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjux NOSPAMyahoo.es> writes:
Hi.

I've writed a getopt module for D (attached to this message) that mostly
follows the POSIX behavior (but it should work on windows too) and is
strongly based on the Python getopt implementation.

Since I'm new to D I would like the people on this newsgroup to test and
review the module and post the comments about it here so we all can improve
our D skills :)

In the header comments, and in the unittest, you'll find a sample of the
module usage.
Feb 12 2004
parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
"Juanjo Álvarez" <juanjux NOSPAMyahoo.es> wrote in message
news:c0g87v$14pt$2 digitaldaemon.com...
| Hi.
|
| I've writed a getopt module for D (attached to this message) that mostly
| follows the POSIX behavior (but it should work on windows too) and is
| strongly based on the Python getopt implementation.
|
| Since I'm new to D I would like the people on this newsgroup to test and
| review the module and post the comments about it here so we all can improve
| our D skills :)
|
| In the header comments, and in the unittest, you'll find a sample of the
| module usage.

Nifty. Some (picky) comments glancing through:
1) using std module assumes it gets into Phobos and becomes ... standard.
2) could use an enum for the errtype values 1, 2 and 3
3) could use some defensive checks for null strings in the char[][] lists
4) could use a foreach in long_has_args
5) include doxygen info (I only say that because I like doxygen...)
6) how much is this like the Python code? Do you have suggestions for guidelines
for this kind of porting?

thanks for sharing,
-Ben
Feb 12 2004
parent Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjux NOSPAMyahoo.es> writes:
Ben Hinkle wrote:


 
 Nifty. Some (picky) comments glancing through:
 1) using std module assumes it gets into Phobos and becomes ... standard.
True, I've changed it, but having it in the standart library would not hurt, its 100% multiplatform and other languages already have a similar module.
 2) could use an enum for the errtype values 1, 2 and 3
Done (enum GetOptError)
 3) could use some defensive checks for null strings in the char[][] lists
Done (two checks added).
 4) could use a foreach in long_has_args
Done (now it is still more Pythonic ;)
 5) include doxygen info (I only say that because I like doxygen...)
Time to learn to use it ;)
 6) how much is this like the Python code? Do you have suggestions for
 guidelines for this kind of porting?
Translating Python into C++ is very easy (I use it a lot for prototyping C++) but I've found that translating Python into D is in fact even easier, variable types translate almost directly, lists translate to dinamic arrays (except for the dinamic resizing, AFAIK), same for dicts to XXXX. Python is extremely dinamic but 99% of the time that is not a problem because a list or a dict in most Python programs will almost always hold the same type along the program, not mixing types in the same struct (and will use the same type as keys in the case of the dict). Python classes are not that different from C++/D/Java classes. The Python "for" easily translates to D "foreach" or to a "while". And array (list) slicing... it's almost the same syntax: Python D ------------------ [:x] [0:x] [x:] [0..array.length] [:-1] [0..array.length-1] ...etc... The fact that most Python programmers come from C++ also helps because you'll find a lot of Python code that is very C++'ish styled. Thanks for your useful comments! PS: The new version of the module is attached, Walter could you please consider it for inclusion into phobos?
Feb 12 2004