Message ID | 20211201053214.2902-1-sunshine@sunshineco.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | CodingGuidelines: document which output goes to stdout vs. stderr | expand |
On 01.12.2021 00:32, Eric Sunshine wrote: >It has long been practice in this project for a command to emit its >primary output to stdout so that it can be captured to a file or sent >down a pipe, and to emit "chatty" messages (such as those reporting >progress) to stderr so that they don't interfere with the primary >output. However, this idiomatic Unix practice is not necessarily >universally understood and may be at odds with other schools of thought, >such as the somewhat common one that only error messages should go to >stderr, and all other messages to stdout. Let's help newcomers by >documenting how stdout and stderr are used on this project. > >Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> >--- > Documentation/CodingGuidelines | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > >diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines >index 711cb9171e..44dd178dc9 100644 >--- a/Documentation/CodingGuidelines >+++ b/Documentation/CodingGuidelines >@@ -499,6 +499,32 @@ For Python scripts: > - Where required libraries do not restrict us to Python 2, we try to > also be compatible with Python 3.1 and later. > >+ >+Program Output >+ >+ We make a distinction between a command's primary output and output >+ which is merely chatty feedback (for instance, status messages, >+ running transcript, or progress display), as well as error messages. >+ Roughly speaking, a command's primary output is that which one might >+ want to capture to a file or send down a pipe; its chatty output >+ should not interfere with those use-cases. >+ >+ As such, primary output should be sent to the standard output stream >+ (stdout), and chatty output should be sent to the standard error >+ stream (stderr). Examples of commands which produce primary output >+ include `git log`, `git show`, and `git branch --list` which generate >+ output on the stdout stream. >+ >+ Not all commands have primary output; this is often true of commands >+ whose main function is to perform an action. Some action commands are >+ silent, whereas others are chatty. An example of a chatty action >+ commands is `git clone` with its "Cloning into '<path>'..." and >+ "Checking connectivity..." status messages which it sends to the >+ stderr stream. >+ >+ Error messages are always sent to the stderr stream. >+ This is not necessarily true in the context of the tests. We just spoke about this in: https://lore.kernel.org/git/211130.86wnkpd6ou.gmgdl@evledraar.gmail.com/T/#u I don't think it necessary to bloat this explanation with the test details. But mentioning it as an exception would be good.
On Wed, Dec 1, 2021 at 3:33 AM Fabian Stelzer <fs@gigacodes.de> wrote: > On 01.12.2021 00:32, Eric Sunshine wrote: > >+ We make a distinction between a command's primary output and output > >+ which is merely chatty feedback (for instance, status messages, > >+ running transcript, or progress display), as well as error messages. > >+ Roughly speaking, a command's primary output is that which one might > >+ want to capture to a file or send down a pipe; its chatty output > >+ should not interfere with those use-cases. > >+ > >+ As such, primary output should be sent to the standard output stream > >+ (stdout), and chatty output should be sent to the standard error > >+ stream (stderr). Examples of commands which produce primary output > >+ include `git log`, `git show`, and `git branch --list` which generate > >+ output on the stdout stream. > >+ > >+ Not all commands have primary output; this is often true of commands > >+ whose main function is to perform an action. Some action commands are > >+ silent, whereas others are chatty. An example of a chatty action > >+ commands is `git clone` with its "Cloning into '<path>'..." and > >+ "Checking connectivity..." status messages which it sends to the > >+ stderr stream. > >+ > >+ Error messages are always sent to the stderr stream. > > This is not necessarily true in the context of the tests. > We just spoke about this in: > https://lore.kernel.org/git/211130.86wnkpd6ou.gmgdl@evledraar.gmail.com/T/#u > > I don't think it necessary to bloat this explanation with the test details. > But mentioning it as an exception would be good. Yep, I tried to be clear about that by repeatedly stating that _command_ output should follow this guideline, where "command" means "Git command". I strongly considered writing "Git command" to be perfectly clear, but figured reviewers would insist that it was redundant to mention "Git". However, I can certainly change these to say "Git command" if you think it would make the intent clearer, and can update the final point to say: Error messages from Git commands should always be sent to the stderr stream.
On 01.12.2021 08:50, Eric Sunshine wrote: >On Wed, Dec 1, 2021 at 3:33 AM Fabian Stelzer <fs@gigacodes.de> wrote: >> On 01.12.2021 00:32, Eric Sunshine wrote: >> >+ We make a distinction between a command's primary output and output >> >+ which is merely chatty feedback (for instance, status messages, >> >+ running transcript, or progress display), as well as error messages. >> >+ Roughly speaking, a command's primary output is that which one might >> >+ want to capture to a file or send down a pipe; its chatty output >> >+ should not interfere with those use-cases. >> >+ >> >+ As such, primary output should be sent to the standard output stream >> >+ (stdout), and chatty output should be sent to the standard error >> >+ stream (stderr). Examples of commands which produce primary output >> >+ include `git log`, `git show`, and `git branch --list` which generate >> >+ output on the stdout stream. >> >+ >> >+ Not all commands have primary output; this is often true of commands >> >+ whose main function is to perform an action. Some action commands are >> >+ silent, whereas others are chatty. An example of a chatty action >> >+ commands is `git clone` with its "Cloning into '<path>'..." and >> >+ "Checking connectivity..." status messages which it sends to the >> >+ stderr stream. >> >+ >> >+ Error messages are always sent to the stderr stream. >> >> This is not necessarily true in the context of the tests. >> We just spoke about this in: >> https://lore.kernel.org/git/211130.86wnkpd6ou.gmgdl@evledraar.gmail.com/T/#u >> >> I don't think it necessary to bloat this explanation with the test details. >> But mentioning it as an exception would be good. > >Yep, I tried to be clear about that by repeatedly stating that >_command_ output should follow this guideline, where "command" means >"Git command". I strongly considered writing "Git command" to be >perfectly clear, but figured reviewers would insist that it was >redundant to mention "Git". > >However, I can certainly change these to say "Git command" if you >think it would make the intent clearer, and can update the final point >to say: > > Error messages from Git commands should always > be sent to the stderr stream. Maybe it was just because i was working on test-lib stuff earlier that i did not connect `a commands output` to a `git command` but basically understood it as all output in git code. Still, I think your addition to the last sentence is a good idea and won't hurt. Thanks
On Wed, Dec 01, 2021 at 12:32:14AM -0500, Eric Sunshine wrote: > It has long been practice in this project for a command to emit its > primary output to stdout so that it can be captured to a file or sent > down a pipe, and to emit "chatty" messages (such as those reporting > progress) to stderr so that they don't interfere with the primary > output. However, this idiomatic Unix practice is not necessarily > universally understood and may be at odds with other schools of thought, > such as the somewhat common one that only error messages should go to > stderr, and all other messages to stdout. Let's help newcomers by > documenting how stdout and stderr are used on this project. I agree with everything you wrote here and below, which I think captures what we want to communicate to folks adding new messages or commands. I am not quite sure _everyone_ would agree with "this idiomatic Unix practice" above. It does seem to be a matter of taste (it is just that what you wrote very much agrees with my taste :) ). And "idiomatic Unix practice" is probably not to be chatty at all, but I think that has been changing over the years. So I'm not sure if your commit message is being nicely assertive about its taste, or is being uncharitable to people who may have different tastes (but again, IMHO we should pick a direction and this seems like the best one to me). :) -Peff
On Wed, Dec 1, 2021 at 2:42 PM Jeff King <peff@peff.net> wrote: > On Wed, Dec 01, 2021 at 12:32:14AM -0500, Eric Sunshine wrote: > > It has long been practice in this project for a command to emit its > > primary output to stdout so that it can be captured to a file or sent > > down a pipe, and to emit "chatty" messages (such as those reporting > > progress) to stderr so that they don't interfere with the primary > > output. However, this idiomatic Unix practice is not necessarily > > universally understood and may be at odds with other schools of thought, > > such as the somewhat common one that only error messages should go to > > stderr, and all other messages to stdout. Let's help newcomers by > > documenting how stdout and stderr are used on this project. > > I agree with everything you wrote here and below, which I think captures > what we want to communicate to folks adding new messages or commands. > > I am not quite sure _everyone_ would agree with "this idiomatic Unix > practice" above. It does seem to be a matter of taste (it is just that > what you wrote very much agrees with my taste :) ). And "idiomatic Unix > practice" is probably not to be chatty at all, but I think that has been > changing over the years. > > So I'm not sure if your commit message is being nicely assertive about > its taste, or is being uncharitable to people who may have different > tastes (but again, IMHO we should pick a direction and this seems like > the best one to me). :) Thanks for the feedback. I'll tone down the commit message when I reroll to make the patch text spell out "Git command" explicitly so that it's less likely to mislead the reader (as it misled Fabian) into thinking the new guideline applies to all output, including test output.
Eric Sunshine <sunshine@sunshineco.com> writes: > However, I can certainly change these to say "Git command" if you > think it would make the intent clearer, and can update the final point > to say: > > Error messages from Git commands should always > be sent to the stderr stream. In an earlier round, I think there was a version without "should" in there, but I am sure we have bugs that do not follow the guideline. The proposed phrasing sounds good to me. Thanks.
On Wed, Dec 1, 2021 at 4:36 PM Junio C Hamano <gitster@pobox.com> wrote: > Eric Sunshine <sunshine@sunshineco.com> writes: > > However, I can certainly change these to say "Git command" if you > > think it would make the intent clearer, and can update the final point > > to say: > > > > Error messages from Git commands should always > > be sent to the stderr stream. > > In an earlier round, I think there was a version without "should" in > there, but I am sure we have bugs that do not follow the guideline. > The proposed phrasing sounds good to me. Yes, the addition of "should" was intentional, though not for any concrete reason (it just felt appropriate). I don't feel strongly either way.
On 01/12/2021 05:32, Eric Sunshine wrote: > It has long been practice in this project for a command to emit its > primary output to stdout so that it can be captured to a file or sent > down a pipe, and to emit "chatty" messages (such as those reporting > progress) to stderr so that they don't interfere with the primary > output. However, this idiomatic Unix practice is not necessarily > universally understood and may be at odds with other schools of thought, > such as the somewhat common one that only error messages should go to > stderr, and all other messages to stdout. Let's help newcomers by > documenting how stdout and stderr are used on this project. > > Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> > --- > Documentation/CodingGuidelines | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines > index 711cb9171e..44dd178dc9 100644 > --- a/Documentation/CodingGuidelines > +++ b/Documentation/CodingGuidelines > @@ -499,6 +499,32 @@ For Python scripts: > - Where required libraries do not restrict us to Python 2, we try to > also be compatible with Python 3.1 and later. > > + > +Program Output > + > + We make a distinction between a command's primary output and output > + which is merely chatty feedback (for instance, status messages, > + running transcript, or progress display), as well as error messages. > + Roughly speaking, a command's primary output is that which one might > + want to capture to a file or send down a pipe; its chatty output > + should not interfere with those use-cases. Is there a case for commenting on whether chatty output may be suppressed if not feeding a terminal, or is that mentioned elsewhere? I often see comments about the isatty() detection. > + > + As such, primary output should be sent to the standard output stream > + (stdout), and chatty output should be sent to the standard error > + stream (stderr). Examples of commands which produce primary output > + include `git log`, `git show`, and `git branch --list` which generate > + output on the stdout stream. > + > + Not all commands have primary output; this is often true of commands > + whose main function is to perform an action. Some action commands are > + silent, whereas others are chatty. An example of a chatty action > + commands is `git clone` with its "Cloning into '<path>'..." and > + "Checking connectivity..." status messages which it sends to the > + stderr stream. > + > + Error messages are always sent to the stderr stream. > + > + > Error Messages > > - Do not end error messages with a full stop. Philip
On Wed, Dec 1, 2021 at 6:27 PM Philip Oakley <philipoakley@iee.email> wrote: > On 01/12/2021 05:32, Eric Sunshine wrote: > > +Program Output > > + > > + We make a distinction between a command's primary output and output > > + which is merely chatty feedback (for instance, status messages, > > + running transcript, or progress display), as well as error messages. > > + Roughly speaking, a command's primary output is that which one might > > + want to capture to a file or send down a pipe; its chatty output > > + should not interfere with those use-cases. > > Is there a case for commenting on whether chatty output may be > suppressed if not feeding a terminal, or is that mentioned elsewhere? I > often see comments about the isatty() detection. I don't think I saw any such mention when reading through CodingGuidelines before composing the new text. That's certainly a topic which could be addressed, but I don't plan on adding it to this patch since I don't have any specific idea in mind for how it would be discussed. However, the new "Program Output" section added by this patch seems a good place to add that discussion if someone wants to have a go at it as a separate patch atop this one.
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 711cb9171e..44dd178dc9 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -499,6 +499,32 @@ For Python scripts: - Where required libraries do not restrict us to Python 2, we try to also be compatible with Python 3.1 and later. + +Program Output + + We make a distinction between a command's primary output and output + which is merely chatty feedback (for instance, status messages, + running transcript, or progress display), as well as error messages. + Roughly speaking, a command's primary output is that which one might + want to capture to a file or send down a pipe; its chatty output + should not interfere with those use-cases. + + As such, primary output should be sent to the standard output stream + (stdout), and chatty output should be sent to the standard error + stream (stderr). Examples of commands which produce primary output + include `git log`, `git show`, and `git branch --list` which generate + output on the stdout stream. + + Not all commands have primary output; this is often true of commands + whose main function is to perform an action. Some action commands are + silent, whereas others are chatty. An example of a chatty action + commands is `git clone` with its "Cloning into '<path>'..." and + "Checking connectivity..." status messages which it sends to the + stderr stream. + + Error messages are always sent to the stderr stream. + + Error Messages - Do not end error messages with a full stop.
It has long been practice in this project for a command to emit its primary output to stdout so that it can be captured to a file or sent down a pipe, and to emit "chatty" messages (such as those reporting progress) to stderr so that they don't interfere with the primary output. However, this idiomatic Unix practice is not necessarily universally understood and may be at odds with other schools of thought, such as the somewhat common one that only error messages should go to stderr, and all other messages to stdout. Let's help newcomers by documenting how stdout and stderr are used on this project. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> --- Documentation/CodingGuidelines | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)