Why I could not cast string to int?
Jonathan M Davis
jmdavisProg at gmx.com
Fri Feb 3 10:10:03 PST 2012
On Friday, February 03, 2012 15:40:34 xancorreu wrote:
> Al 02/02/12 20:40, En/na Jonathan M Davis ha escrit:
> > And whether that's the best way to handle it depends on what you're
> > trying to do in terms of user input and error messages. How on earth
> > is all of that going to be handled generically? It all depends on what
> > the programmer is trying to do. Switching to use command-line switches
> > and getopt would help some, but you still have to deal with the error
> > messages yourself. Creating the Person is the easy part. - Jonathan M
> > Davis
>
> I think it as a tool, not solve-everything-thing, it just a tool for
> easy your job. Yeah, you could manually do that (thanks for the code)
> but really you, maybe, want to do it _fastest_ and _easyest_.
Fastest and easiest would be to simply do
auto person = person(args[1], to!uint(args[2]), to!bool(args[3]));
but that's going to blow up in your face in all sorts of entertaining ways if
you didn't do verify the arguments that the user gave you (both in terms of
number and their values). And it's so easy to do, that I don't see much point
in trying to have some sort of function or library for automatically
generating your object from the program's arguments - especially when you
really should be doing argument validation, which no one else can do for you,
since the correct way to do it is completely dependent on your application.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list