unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Source code formatting: line length limit?
@ 2003-01-25 12:39 Kai Großjohann
  2003-01-25 13:26 ` Robert J. Chassell
  0 siblings, 1 reply; 10+ messages in thread
From: Kai Großjohann @ 2003-01-25 12:39 UTC (permalink / raw)


Until recently, I've implicitly assumed that lines should not exceed
79 or so columns.

But now I'd like to know, rather than just assume :-)
-- 
Ambibibentists unite!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-25 12:39 Source code formatting: line length limit? Kai Großjohann
@ 2003-01-25 13:26 ` Robert J. Chassell
  2003-01-26  1:21   ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Robert J. Chassell @ 2003-01-25 13:26 UTC (permalink / raw)
  Cc: emacs-devel

   Until recently, I've implicitly assumed that lines should not exceed
   79 or so columns.

70 columns is better, since that length enables readers to quote you
readily and to send easily readable patches.

Moreover, over the past half millenium, printers have found that
people have difficulty swinging their eyes down to the next line when
the line is too long or when the between-line spacing is too wide or
too narrow.  A fill-column of 70 works well with the usual
between-line spacing on a computer screen.  (Shorter lines work well
with the usual between-line spacing of printed books.)

As 
    File: elisp,  Node: Margins
says

     As a practical matter, if you are writing text for other people
     to read, you should set `fill-column' to no more than 70.
     Otherwise the line will be too long for people to read
     comfortably, and this can make the text seem clumsy.
     ....
     The default value for `default-fill-column' is 70.

While these remarks apply to people writing sentences and paragraphs,
they also apply to people writing code.

-- 
    Robert J. Chassell                         Rattlesnake Enterprises
    http://www.rattlesnake.com                  GnuPG Key ID: 004B4AC8
    http://www.teak.cc                                     bob@gnu.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-25 13:26 ` Robert J. Chassell
@ 2003-01-26  1:21   ` Stefan Monnier
  2003-01-26 13:12     ` Robert J. Chassell
  2003-01-26 14:48     ` Kai Großjohann
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2003-01-26  1:21 UTC (permalink / raw)
  Cc: Kai Großjohann

> Moreover, over the past half millenium, printers have found that
> people have difficulty swinging their eyes down to the next line when
> the line is too long or when the between-line spacing is too wide or
> too narrow.  A fill-column of 70 works well with the usual
> between-line spacing on a computer screen.  (Shorter lines work well
> with the usual between-line spacing of printed books.)

Note that in source code, most lines don't start in column 0, so for
a given line, the number of columns of text is not necessarily the same
as the column of the rightmost char.

I happen to think that 60 columns is more legible, but I also think
that in most cases, source code that spans 80 columns is perfectly legible
because almost none of the lines actually takes more than 60 columns
of text.  Also the non-constant indentation of the code also helps
your eyes find the next line.

And since I find vertical screen-real-estate to be at a premium, I advocate
using all 80 columns for code (text is obviously another matter).


	Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26  1:21   ` Stefan Monnier
@ 2003-01-26 13:12     ` Robert J. Chassell
  2003-01-27  2:32       ` Richard Stallman
  2003-01-27 14:14       ` Stefan Monnier
  2003-01-26 14:48     ` Kai Großjohann
  1 sibling, 2 replies; 10+ messages in thread
From: Robert J. Chassell @ 2003-01-26 13:12 UTC (permalink / raw)


I wrote:

   > ....  A fill-column of 70 works well with the usual
   > between-line spacing on a computer screen.

"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> responds

   Note that in source code, most lines don't start in column 0, so for
   a given line, the number of columns of text is not necessarily the same
   as the column of the rightmost char.

   I happen to think that 60 columns is more legible,  ...

Yes.  In some ways, 60 is better; it is even harder to swing your eyes
down when the lines do not start in the left most column.

However, one advantage of a wider line is that more information is put
on the line.  Programming expressions are ways of stating complex
notions in a manner than a human can comprehend.  It is easier to
understand and bear in mind a notion laid out in one line than spread
out over two or three.  A key characteristic of programming languages
designed for programmers, such as C or Lisp, is that they are
succinct.

On the other hand, excessive width does reduce the compactness of a
notation as much as excessive depth, so a line cannot be overly long.

(Excessive succinctness creates another problem; many programmers find
it hard to comprehend a expression that is `too concise', for some
fuzzy definition of `too concise'.  A popular programming language
must be a balance between `too concise' and `too wordy'.)

   .... but I also think that in most cases, source code that spans 80
   columns is perfectly legible because almost none of the lines
   actually takes more than 60 columns of text.
   ... 
   Also the non-constant indentation of the code also helps
   your eyes find the next line.

Indentation helps, but large areas of blank space on the left give
difficulty to me nonetheless.

   And since I find vertical screen-real-estate to be at a premium, I advocate
   using all 80 columns for code (text is obviously another matter).

An 80 column text looks terrible when patched or quoted so as to be
wider, but still shown on an 80 column window.  Consequently, an 80
column width will discourage some from quoting or patching your code,
since he or she will have to pretty print it before working on it.

-- 
    Robert J. Chassell                         Rattlesnake Enterprises
    http://www.rattlesnake.com                  GnuPG Key ID: 004B4AC8
    http://www.teak.cc                                     bob@gnu.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26  1:21   ` Stefan Monnier
  2003-01-26 13:12     ` Robert J. Chassell
@ 2003-01-26 14:48     ` Kai Großjohann
  2003-01-26 18:49       ` Robert J. Chassell
                         ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: Kai Großjohann @ 2003-01-26 14:48 UTC (permalink / raw)


"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> writes:

> I happen to think that 60 columns is more legible, but I also think
> that in most cases, source code that spans 80 columns is perfectly legible
> because almost none of the lines actually takes more than 60 columns
> of text.

I think both of you implicitly imply that text *over* 80 columns is
bad and should be avoided.

Could you make this explicit?

To illustrate my problem:  I have just reformatted source code from
something like 120 columns to something below 80.  Should I revert
this change, making the lines longer again?  Some of the changes
produced rather awful-looking code because the code is nested very
deeply.
-- 
Ambibibentists unite!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26 14:48     ` Kai Großjohann
@ 2003-01-26 18:49       ` Robert J. Chassell
  2003-01-27  2:32       ` Richard Stallman
  2003-01-27 13:01       ` Stefan Monnier
  2 siblings, 0 replies; 10+ messages in thread
From: Robert J. Chassell @ 2003-01-26 18:49 UTC (permalink / raw)


   I think both of you implicitly imply that text *over* 80 columns is
   bad and should be avoided.

Yes.

   To illustrate my problem:  I have just reformatted source code from
   something like 120 columns to something below 80.  

Good.  There are several different reasons to prefer less than 80
columns:

  * Consider someone who is interested in your code: most likely he or
    she is viewing it in an 80 column width window or on a terminal
    with no more than 80 columns.  Not everyone uses 80
    columns or less, but large numbers do.

    If your reader uses 80 columns or less, either your reader
    reformats the code or widens the window (assuming the latter
    action is possible) Either way makes for more work for your
    reader, and less likelihood that your code will be studied as
    thoroughly as you would like.

  * Again, consider someone who is interested in your code: one of
    your readers may be different, but over the past 500 years,
    printers have found that most readers tend to have a hard time
    moving their eyes from one line to another unless the text
    posseses the right balance of line length and between-line blank
    space.

    One old `rule of thumb' for determining maximum line length was
    `twice the alphabet plus the punctuation'.  For English readers,
    this leads to line lengths in the 60s, depending on what you
    consider to be punctuation.  Computer displays often use a little
    more inter-line spacing than printed books, and tend to do well
    with a maximum line length of 70.

  * Determining line length for computer code is harder than for text,
    because of the advantage of conciseness.  A programmer reading
    your code may well have an easier time understanding a single
    expression that is all on one line than the same expression split
    over several lines.  So that favors longer linges.

    On the other hand, no one can readily ready code that goes beyound
    the right hand boundary of the screen, regardless whether the line
    is truncated or wrapped at the 80th character.  Hence, it is a
    good idea to make sure the right hand side of the line is less
    than 80 characters from the left.

    At the same time, code is often indented.  In general, this is an
    advantage; but at the same time, the reader may get lost in the
    blank space to the left of the code.  To counter this problem, I
    often delimit expressions using GNU Emacs' parenthesis balancing
    feature.  But at the same time, I also make use of indenting; for
    example, just yesterday, I ran `pp' on the automatically
    generated, unforatted code that records a spreadsheet in Emacs
    Dismal mode, so I could read it.

-- 
    Robert J. Chassell                         Rattlesnake Enterprises
    http://www.rattlesnake.com                  GnuPG Key ID: 004B4AC8
    http://www.teak.cc                                     bob@gnu.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26 13:12     ` Robert J. Chassell
@ 2003-01-27  2:32       ` Richard Stallman
  2003-01-27 14:14       ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2003-01-27  2:32 UTC (permalink / raw)
  Cc: emacs-devel

I think that program code should usually have less than 40 characters
of real text on a line.  But that is not counting the line's
indentation.  Sometimes it is hard to avoid getting out towards
column 80.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26 14:48     ` Kai Großjohann
  2003-01-26 18:49       ` Robert J. Chassell
@ 2003-01-27  2:32       ` Richard Stallman
  2003-01-27 13:01       ` Stefan Monnier
  2 siblings, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2003-01-27  2:32 UTC (permalink / raw)
  Cc: emacs-devel

    To illustrate my problem:  I have just reformatted source code from
    something like 120 columns to something below 80.

Sometimes, in such cases, the best solution is to move some of the
deeply nested code into subroutines.  That reduces the nesting,
and enables you to keep the code within 80 columns easily without
requiring lots of line breaks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26 14:48     ` Kai Großjohann
  2003-01-26 18:49       ` Robert J. Chassell
  2003-01-27  2:32       ` Richard Stallman
@ 2003-01-27 13:01       ` Stefan Monnier
  2 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2003-01-27 13:01 UTC (permalink / raw)
  Cc: emacs-devel

> I think both of you implicitly imply that text *over* 80 columns is
> bad and should be avoided.
> 
> Could you make this explicit?

Yes, I think one or two lines slightly over 80 chars are OK as long as
there's a good justification for them and as long as they're not all
next to each other.

> To illustrate my problem:  I have just reformatted source code from
> something like 120 columns to something below 80.  Should I revert
> this change, making the lines longer again?  Some of the changes
> produced rather awful-looking code because the code is nested very
> deeply.

If it's nested too deeply, it's sometimes difficult to place
LF such that the indentation looks good and the code readable,
but most of the time, it's just difficult to read no matter what
and should thus be split out into a separate function.

120 is way over what I consider as acceptable: it's basically unreadable.


	Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Source code formatting: line length limit?
  2003-01-26 13:12     ` Robert J. Chassell
  2003-01-27  2:32       ` Richard Stallman
@ 2003-01-27 14:14       ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2003-01-27 14:14 UTC (permalink / raw)
  Cc: emacs-devel

> An 80 column text looks terrible when patched or quoted so as to be
> wider, but still shown on an 80 column window.  Consequently, an 80

That's tru for text but much less for code because the length of
the lines is typically a lot more variable, so if the whole
code fits within 80 columns, that means that typically very few lines
will overflow after quoting.


	Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-01-27 14:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-25 12:39 Source code formatting: line length limit? Kai Großjohann
2003-01-25 13:26 ` Robert J. Chassell
2003-01-26  1:21   ` Stefan Monnier
2003-01-26 13:12     ` Robert J. Chassell
2003-01-27  2:32       ` Richard Stallman
2003-01-27 14:14       ` Stefan Monnier
2003-01-26 14:48     ` Kai Großjohann
2003-01-26 18:49       ` Robert J. Chassell
2003-01-27  2:32       ` Richard Stallman
2003-01-27 13:01       ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).