[PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

Subsystems: documentation, the rest

STALE1728d

10 messages, 4 authors, 2021-12-02 · open the first message on its own page

[PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Eric Sunshine <hidden>
Date: 2021-12-01 05:33:24

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 <redacted>
---
 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.
+
+
 Error Messages
 
  - Do not end error messages with a full stop.
-- 
2.34.1.75.gabe6bb3905

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Fabian Stelzer <hidden>
Date: 2021-12-01 08:33:08

On 01.12.2021 00:32, Eric Sunshine wrote:
quoted hunk
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 <redacted>
---
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.

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Eric Sunshine <hidden>
Date: 2021-12-01 13:54:15

On Wed, Dec 1, 2021 at 3:33 AM Fabian Stelzer [off-list ref] wrote:
On 01.12.2021 00:32, Eric Sunshine wrote:
quoted
+ 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.

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Fabian Stelzer <hidden>
Date: 2021-12-01 15:15:16

On 01.12.2021 08:50, Eric Sunshine wrote:
On Wed, Dec 1, 2021 at 3:33 AM Fabian Stelzer [off-list ref] wrote:
quoted
On 01.12.2021 00:32, Eric Sunshine wrote:
quoted
+ 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

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Jeff King <hidden>
Date: 2021-12-01 19:42:45

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

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Eric Sunshine <hidden>
Date: 2021-12-01 20:30:29

On Wed, Dec 1, 2021 at 2:42 PM Jeff King [off-list ref] wrote:
On Wed, Dec 01, 2021 at 12:32:14AM -0500, Eric Sunshine wrote:
quoted
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.

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Philip Oakley <hidden>
Date: 2021-12-01 23:27:26

On 01/12/2021 05:32, Eric Sunshine wrote:
quoted hunk
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 <redacted>
---
 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

Re: [PATCH] CodingGuidelines: document which output goes to stdout vs. stderr

From: Eric Sunshine <hidden>
Date: 2021-12-01 23:56:28

On Wed, Dec 1, 2021 at 6:27 PM Philip Oakley [off-list ref] wrote:
On 01/12/2021 05:32, Eric Sunshine wrote:
quoted
+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.

[PATCH v2] CodingGuidelines: document which output goes to stdout vs. stderr

From: Eric Sunshine <hidden>
Date: 2021-12-02 22:32:08

It has long been practice on 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 practice is not necessarily universal; another
common practice is to send only error messages to stderr, and all other
messages to stdout. Therefore, help newcomers out by documenting how
stdout and stderr are used on this project.

Signed-off-by: Eric Sunshine <redacted>
---

Changes since v1[*]:

* tone down the commit message (peff)

* replace "command" in the patch body with "Git command" in a few places
  to make it more clear that the new "Program Output" section is
  providing guidelines for how Git commands should behave, as opposed
  to, say, how stdout/stderr should be used in test scripts (fabian)

No interdiff/range-diff since they are too noisy in this case, and the
patch is short enough to easily re-read in its entirety.

[*]: https://lore.kernel.org/git/20211201053214.2902-1-sunshine@sunshineco.com/

 Documentation/CodingGuidelines | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 711cb9171e..0e27b5395d 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -499,6 +499,33 @@ 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 Git 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 Git 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 these 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 Git 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 from Git commands should always be sent to the stderr
+ stream.
+
+
 Error Messages
 
  - Do not end error messages with a full stop.
-- 
2.34.1.173.g76aa8bc2d0

Re: [PATCH v2] CodingGuidelines: document which output goes to stdout vs. stderr

From: Jeff King <hidden>
Date: 2021-12-02 23:58:48

On Thu, Dec 02, 2021 at 05:31:10PM -0500, Eric Sunshine wrote:
It has long been practice on 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 practice is not necessarily universal; another
common practice is to send only error messages to stderr, and all other
messages to stdout. Therefore, help newcomers out by documenting how
stdout and stderr are used on this project.

Signed-off-by: Eric Sunshine <redacted>
---

Changes since v1[*]:

* tone down the commit message (peff)
:) This looks great to me. Thanks for doing it.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help