views:

204

answers:

2

Does anyone know the original rationale, or story, of the different platforms each choosing a different, yet similar to some degree, new line representation? There must be some design decisions made originally. (I don't believe this is all random choice ...)

  • Unix/Mac OS X: LF (\n)
  • Mac OS 9 and before: CR (\r)
  • DOS/Windows: CRLF (\r\n)
+1  A: 

Well, \r\n is Carriage Return then Linefeed, which is the same sequence of keys used to start a new line from the left column on a typewriter.

taspeotis
+8  A: 

Jeff Atwood posted on this very topic in "The Great Newline Schism"

Wikipedia covers the history of newline.

In short, CR+LF is a reference to the electric typewriter days when you would first use a carriage return to move the cursor to the left and a line feed to move down a line. You would occasionally just use one or the other for writing special characters such as underline or strike-through.

CRLF

Computers adopted this nomenclature as it was useful for interacting with teletype machines. This is why MS-DOS and subsequently Windows use CRLF.

LF

Apparently, Multics and subsequently Unix took their cue from the 1963-64 draft of the ISO draft standards which indicated that either CRLF or LF could represent newline, and went with the single LF character.

CR

I'm still a bit puzzled about the history of apple adopting CR. I'm looking into it... So far, my best guess is that this is due to apple's early distinction between the enter and return keys. In the early days, the return key mapped to a carriage return and the enter key to a line feed, rather than having a single "enter" key that does double duty, like in the Windows world. To typewriter users, who would routinely use the carriage return for special formatting, this may have made sense to separate the two and apple did, in fact, use the return key for special formatting options.

Where I'm not so sure is how, when they abandoned this, they settled on just using CR, but my guess is it dates to this early decision to use CR for the return key...but I may be wrong.

Michael La Voie