Why D Needs Attributes (Was: Command-line arguments)

Bruce Adams tortoise_74 at yeah.who.co.uk
Sat Jul 5 03:30:28 PDT 2008


On Sat, 05 Jul 2008 06:05:39 +0100, Dee Girl <deegirl at noreply.com> wrote:
>
> Also the modular part is not good argument. Code to handle command line  
> is unique, never called from the app. Only once. Should be there in  
> line. Design for modular there is not justified. I think even is  
> mistake. Parse arguments is simple problem and should have simple  
> solution. std.getopt is simple solution. (only one function!) All other  
> are complicated. It means they did not see how simple problem is. Thank  
> you, Dee Girl

Code to handle *a* command line is not always unique. argv is only one  
possible
source. Imagine you are implementing a shell with several builtin  
commands. These
commands will have options that need to be parsed.

Still if I had to vote and it was based purely on the discussions so far  
(ignoring the rudeness)
I would go for getopt. Fortunately getopt in D is nothing like the gnarly  
beast that getopt is in C.

I don't think the three items required by getopt are redundant. They  
provide different information.
The variable declaration gives the type. You could only avoid this by  
making arguments a special type
like stringArg: public Arg which tends to overcomplicate things.
As has already been pointed out there is not necessarily a one-to-one  
mapping between the variable name
and the option name. Especially if you have different conventions to  
conform to for your user interface
and your code. Assuming your users always have the same requirements as  
programmers is a bad thing.
That said providing a default mapping and a way to override it does make  
sense.

None of the discussion so far has provided a decent use case for why we  
need C# style attributes or
even a definition of them for those in the group less familiar with them.  
If there is one I doubt its
going to come from the command line.

Regards,

Bruce.



More information about the Digitalmars-d mailing list