tags:

views:

271

answers:

2

Are there any conventions for formatting console output from a command line app for readability and consistency? For instance, do you indent sub-information, when do you print a blank line, if ever, how should you accent important statements.

I've found output can quickly degenerate into a chaotic blur. I'm interested in hearing about what other people do.

Update: Really this is for embedded software which spits debug status out a terminal, but it's pretty much like a console app, and I figured everyone would be more familiar with that. Thanks so far.

+1  A: 

I'd differentiate two kinds of programs:

Do you print information that might be used by a script (i.e. it should be parseable)? Then define a pretty strict format and use only that (for example fixed field separators).

Do you print information that need not be parsed by a script (or is there an alternative script-parseable format already)? Then write what comes natural:

My suggestions:

  • write it so that you would like to read it
  • indent sub-information 2 or 4 spaces, definitely not more
  • separate blocks of information by one empty line at most
  • respect the COLUMN environment variable (and possible ROWS if it applies to your output).
Joachim Sauer
+1  A: 

If this is for a *nix environment, then I'd recommend reading Basics of Unix Philosophy. It's not specific to output but there are some good guidelines for command line programs in general.

Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't insist on interactive input.

codelogic