www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Return value from getopt?

reply "Janice Caron" <caron800 googlemail.com> writes:
In the documentation for std.getopt, the function

    bool getopt(T...)(ref string[] args, T opts);

is documented. All the inputs are well described, however, the meaning
of the return value is not described at all. All of the example code
disregards the return value completely. We are given absolutely no
clue as to what the return value means.

If I had to guess, I'd guess that true means success and false means
failure ... or possibly the other way round. But ... if either of
these possibilities are true, then surely that violates the D
principles established in the document

    http://digitalmars.com/d/2.0/errors.html

To quote bits of that: To deal with these possible errors, tedious
error handling code must be added to each function call.  ...  Good
error handling code tends to clutter up what otherwise would be a neat
and clean looking implementation. ...

It basically goes on to say that "the D way" is just to throw an
exception if things go wrong.

So my question is: is the return value of getopt meaningful, or is it
just an error indicator?

If the first case, please can it be documented?
If the second case, please can the function signature be changed to
return void, and an exception thrown on error?

Thanks
Jan 23 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Janice Caron" <caron800 googlemail.com> wrote in message 
news:mailman.14.1201077872.5260.digitalmars-d puremagic.com...

 If I had to guess, I'd guess that true means success and false means
 failure ... or possibly the other way round. But ... if either of
 these possibilities are true, then surely that violates the D
 principles established in the document
You don't have to guess. The source code for Phobos is available for your perusal in every D compiler distribution. And you're right, it just returns true for success and false for failure.
 If the second case, please can the function signature be changed to
 return void, and an exception thrown on error?
It probably should..
Jan 23 2008
next sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On Jan 23, 2008 2:26 PM, Jarrett Billingsley <kb3ctd2 yahoo.com> wrote:
 You don't have to guess.  The source code for Phobos is available for your
 perusal in every D compiler distribution.  And you're right, it just returns
 true for success and false for failure.
Good point. I hadn't thought of that. For some mad reason I keep expecting the documentation to be enough! :-)
 If the second case, please can the function signature be changed to
 return void, and an exception thrown on error?
It probably should..
In that case, I'd like to request of Walter that this be changed. Otherwise, all of my code which uses getopt will have to do lots of ugly error checking of the return code. Moreover, if it fails, there's no obvious way to find out why it failed, wheras an exception could carry that information.
Jan 23 2008
prev sibling parent Brad Roberts <braddr puremagic.com> writes:
Janice Caron wrote:
 On Jan 23, 2008 2:26 PM, Jarrett Billingsley <kb3ctd2 yahoo.com> wrote:
 You don't have to guess.  The source code for Phobos is available for your
 perusal in every D compiler distribution.  And you're right, it just returns
 true for success and false for failure.
Good point. I hadn't thought of that. For some mad reason I keep expecting the documentation to be enough! :-)
 If the second case, please can the function signature be changed to
 return void, and an exception thrown on error?
It probably should..
In that case, I'd like to request of Walter that this be changed. Otherwise, all of my code which uses getopt will have to do lots of ugly error checking of the return code. Moreover, if it fails, there's no obvious way to find out why it failed, wheras an exception could carry that information.
... bugzilla. :)
Jan 23 2008