Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-12 Thread Timothy Brownawell
On Sun, 2009-01-04 at 11:14 -0800, Zack Weinberg wrote:
> >> > A command that does "throw usage()" gives the same result as calling
> >> > "mtn help ", printing full usage info to stderr, where N()
> >> > results in "mtn: misuse: " on stderr and will put a note in any
> >> > debug log.
> >>
> >> As long as the  is maintained in case of "throw usage()", I'm
> >> fine. I dislike tools which just throw the complete usage page at me and
> >> let me figure myself. Some hint on what's wrong certainly helps. And
> >> that hint should survive, IMO.
> >
> > So I guess we should standardize on "throw usage()", but give usage a
> > what() and make the constructor take a message.
> 
> I'm dubious about printing the full usage message on any command line
> mistake.  Those are often long enough that they make the actual
> diagnostic scroll off the top of the terminal or at least be visually
> lost in a sea of chatter.

Hmm, plus there's the question of where to draw the line. Wrong number
of arguments (easy)? Missing required --options? Options that are only
required because of the number of arguments (like with 'mtn revert')?
Nonsensical combinations of options (--message with --message-file)?
Invalid argument types ('mtn approve not_a_revision_id')? Any
distinction would be somewhat arbitrary, and therefore
annoying/confusing...

> What would be really good is if we could give customized usage advice
> based on the error, e.g. currently we have
> 
> $ mtn ls
> mtn: misuse: no subcommand specified for 'ls'
> 
> but 'mtn help ls' prints a 55-line message the relevant part of which
> is in the *middle.*  It would be great if we could extract just the
> "subcommands of 'mtn ls'" part of that message and print it after the
> above diagnostic.
> 
> zw



___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread Thomas Keller
Zack Weinberg schrieb:
 A command that does "throw usage()" gives the same result as calling
 "mtn help ", printing full usage info to stderr, where N()
 results in "mtn: misuse: " on stderr and will put a note in any
 debug log.
>>> As long as the  is maintained in case of "throw usage()", I'm
>>> fine. I dislike tools which just throw the complete usage page at me and
>>> let me figure myself. Some hint on what's wrong certainly helps. And
>>> that hint should survive, IMO.
>> So I guess we should standardize on "throw usage()", but give usage a
>> what() and make the constructor take a message.
> 
> I'm dubious about printing the full usage message on any command line
> mistake.  Those are often long enough that they make the actual
> diagnostic scroll off the top of the terminal or at least be visually
> lost in a sea of chatter.
> 
> What would be really good is if we could give customized usage advice
> based on the error, e.g. currently we have
> 
> $ mtn ls
> mtn: misuse: no subcommand specified for 'ls'
> 
> but 'mtn help ls' prints a 55-line message the relevant part of which
> is in the *middle.*  It would be great if we could extract just the
> "subcommands of 'mtn ls'" part of that message and print it after the
> above diagnostic.

And while we're at it I'd like to add some --show-global-options option
to `mtn help' to prevent the additional 22 line output of global options
which should be commonly known to users. Or have some `mtn help options'
command which does exactly that.

Thomas

-- 
GPG-Key 0x160D1092 | tommyd3...@jabber.ccc.de | http://thomaskeller.biz
Please note that according to the EU law on data retention, information
on every electronic information exchange might be retained for a period
of six months or longer: http://www.vorratsdatenspeicherung.de/?lang=en



signature.asc
Description: OpenPGP digital signature
___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread Zack Weinberg
On Sun, Jan 4, 2009 at 10:30 AM, Timothy Brownawell  wrote:
> On Sun, 2009-01-04 at 18:41 +0100, Markus Wanner wrote:
>> Timothy Brownawell wrote:
>> > "N(false, message)" results in "throw informative_faulure(message)", the
>> > question is what to throw rather than whether to throw.
>>
>> I'm with Timothy on that. These states are exceptional enough and much
>> simpler to code. While "control loops" (why a loop, simple conditions
>> would do, no?) clutter .. ehm.. exception handling a lot.

Yes, especially in the present state where command-line errors are
detected within the CMD() function, which is several levels down from
the code that generates the usage message.  It really is an
exceptional transfer of control.

>> > A command that does "throw usage()" gives the same result as calling
>> > "mtn help ", printing full usage info to stderr, where N()
>> > results in "mtn: misuse: " on stderr and will put a note in any
>> > debug log.
>>
>> As long as the  is maintained in case of "throw usage()", I'm
>> fine. I dislike tools which just throw the complete usage page at me and
>> let me figure myself. Some hint on what's wrong certainly helps. And
>> that hint should survive, IMO.
>
> So I guess we should standardize on "throw usage()", but give usage a
> what() and make the constructor take a message.

I'm dubious about printing the full usage message on any command line
mistake.  Those are often long enough that they make the actual
diagnostic scroll off the top of the terminal or at least be visually
lost in a sea of chatter.

What would be really good is if we could give customized usage advice
based on the error, e.g. currently we have

$ mtn ls
mtn: misuse: no subcommand specified for 'ls'

but 'mtn help ls' prints a 55-line message the relevant part of which
is in the *middle.*  It would be great if we could extract just the
"subcommands of 'mtn ls'" part of that message and print it after the
above diagnostic.

zw


___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread Timothy Brownawell
On Sun, 2009-01-04 at 18:41 +0100, Markus Wanner wrote:
> Hi,
> 
> Timothy Brownawell wrote:
> > "N(false, message)" results in "throw informative_faulure(message)", the
> > question is what to throw rather than whether to throw.
> 
> I'm with Timothy on that. These states are exceptional enough and much
> simpler to code. While "control loops" (why a loop, simple conditions
> would do, no?) clutter .. ehm.. exception handling a lot.
> 
> > A command that does "throw usage()" gives the same result as calling
> > "mtn help ", printing full usage info to stderr, where N()
> > results in "mtn: misuse: " on stderr and will put a note in any
> > debug log.
> 
> As long as the  is maintained in case of "throw usage()", I'm
> fine. I dislike tools which just throw the complete usage page at me and
> let me figure myself. Some hint on what's wrong certainly helps. And
> that hint should survive, IMO.

So I guess we should standardize on "throw usage()", but give usage a
what() and make the constructor take a message.


-- 
Timothy

Free (experimental) public monotone hosting: http://mtn-host.prjek.net



___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread Markus Wanner
Hi,

LeJacq, Jean Pierre wrote:
> Two considerations:
> 
> 1. N() can always be modified to provide an alternate implementation,
>though I acknowledge that changing from throw semantics
>would be problematic. For example, adding logging before the throw.

Isn't this exactly what Timothy proposes? Clearer separation of the two.

> 2. N() is not the best choice for handling this to begin with.

Agreed. Timothy proposed using "throw usage();" instead, which is
according to these two requests, AFAICT.

Regards

Markus Wanner


___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread LeJacq, Jean Pierre
On Sunday 2009 January 04 11:41:46 Timothy Brownawell wrote:
> On Sun, 2009-01-04 at 11:24 -0500, LeJacq, Jean Pierre wrote:
> > On Saturday 2009 January 03 20:56:52 Timothy Brownawell wrote:
> > > Many commands check for eg the right number of arguments like so:
> > >
> > >   if (args.size() != 3)
> > > throw usage(execid);
> > >
> > > where others do
> > >
> > >   N(args.size() == 0,
> > > F("no arguments needed"));
> > >
> > >
> > > This ought to be made consistent, does anyone object to using the
> > > 'throw usage();' version everywhere?
> >
> > I recommend the inverse. Exceptions should be reserved for, well
> > "exceptional" situations. Validation of inputs doesn't fall into
> > this category and is more properly handled by normal control loops.
>
> "N(false, message)" results in "throw informative_faulure(message)", the
> question is what to throw rather than whether to throw.

Two considerations:

1. N() can always be modified to provide an alternate implementation,
   though I acknowledge that changing from throw semantics
   would be problematic. For example, adding logging before the throw.
2. N() is not the best choice for handling this to begin with.

-- 
JP


___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread Markus Wanner
Hi,

Timothy Brownawell wrote:
> "N(false, message)" results in "throw informative_faulure(message)", the
> question is what to throw rather than whether to throw.

I'm with Timothy on that. These states are exceptional enough and much
simpler to code. While "control loops" (why a loop, simple conditions
would do, no?) clutter .. ehm.. exception handling a lot.

> A command that does "throw usage()" gives the same result as calling
> "mtn help ", printing full usage info to stderr, where N()
> results in "mtn: misuse: " on stderr and will put a note in any
> debug log.

As long as the  is maintained in case of "throw usage()", I'm
fine. I dislike tools which just throw the complete usage page at me and
let me figure myself. Some hint on what's wrong certainly helps. And
that hint should survive, IMO.

Regards

Markus Wanner


___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread Timothy Brownawell
On Sun, 2009-01-04 at 11:24 -0500, LeJacq, Jean Pierre wrote:
> On Saturday 2009 January 03 20:56:52 Timothy Brownawell wrote:
> > Many commands check for eg the right number of arguments like so:
> >
> >   if (args.size() != 3)
> > throw usage(execid);
> >
> > where others do
> >
> >   N(args.size() == 0,
> > F("no arguments needed"));
> >
> >
> > This ought to be made consistent, does anyone object to using the
> > 'throw usage();' version everywhere?
> 
> I recommend the inverse. Exceptions should be reserved for, well
> "exceptional" situations. Validation of inputs doesn't fall into
> this category and is more properly handled by normal control loops.

"N(false, message)" results in "throw informative_faulure(message)", the
question is what to throw rather than whether to throw.

A command that does "throw usage()" gives the same result as calling
"mtn help ", printing full usage info to stderr, where N()
results in "mtn: misuse: " on stderr and will put a note in any
debug log.


-- 
Timothy

Free (experimental) public monotone hosting: http://mtn-host.prjek.net



___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-04 Thread LeJacq, Jean Pierre
On Saturday 2009 January 03 20:56:52 Timothy Brownawell wrote:
> Many commands check for eg the right number of arguments like so:
>
>   if (args.size() != 3)
> throw usage(execid);
>
> where others do
>
>   N(args.size() == 0,
> F("no arguments needed"));
>
>
> This ought to be made consistent, does anyone object to using the
> 'throw usage();' version everywhere?

I recommend the inverse. Exceptions should be reserved for, well
"exceptional" situations. Validation of inputs doesn't fall into
this category and is more properly handled by normal control loops.

-- 
JP


___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


Re: [Monotone-devel] "throw usage(); " or "N(); " for argument checking?

2009-01-03 Thread Thomas Keller
Timothy Brownawell schrieb:
> Many commands check for eg the right number of arguments like so:
> 
>   if (args.size() != 3)
> throw usage(execid);
> 
> where others do
> 
>   N(args.size() == 0,
> F("no arguments needed"));
> 
> 
> This ought to be made consistent, does anyone object to using the
> 'throw usage();' version everywhere?

The only thing which comes into my mind is the automation interface here
- we don't want to provide the full-blown (localized) help output to the
interface here, but rather a hint that the call wasn't syntactically
correct.

This reminds me on something I have on my wishlist - while syntactic
option errors (ie. an option does not exist or is invalid for a given
command) are handled before a command is executed, the argument checking
happens in the command itself. This is usually not a problem, unless we
really want to distinguish between syntax errors and other runtime
errors f.e. in automate...

Thomas.

-- 
GPG-Key 0x160D1092 | tommyd3...@jabber.ccc.de | http://thomaskeller.biz
Please note that according to the EU law on data retention, information
on every electronic information exchange might be retained for a period
of six months or longer: http://www.vorratsdatenspeicherung.de/?lang=en



signature.asc
Description: OpenPGP digital signature
___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel


[Monotone-devel] "throw usage();" or "N();" for argument checking?

2009-01-03 Thread Timothy Brownawell
Many commands check for eg the right number of arguments like so:

  if (args.size() != 3)
throw usage(execid);

where others do

  N(args.size() == 0,
F("no arguments needed"));


This ought to be made consistent, does anyone object to using the
'throw usage();' version everywhere?


-- 
Timothy

Free (experimental) public monotone hosting: http://mtn-host.prjek.net



___
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel