views:

1196

answers:

2

In JavaScript this was a cross-browser compatibility issue, so both were used, but there are numerous instances in different languages where I see both printed out together as \r\n. Is this still the generally excepted norm that you should just always use both, or is there ever a time where languages understand both and you end up with a break and a return?

+7  A: 

The CRLF pair is the expected end-of-line (EOL) marker on most internet protocols.

Here, Postel's "Robustness Principle" should apply. Be liberal in what you accept, but strict in what you send. So, be prepared to receive just a LF, but if you're sending data use whatever the relevant standards require.

Alnitak
Robustness principle is the cause for HTML soup. Damn the principle! :-)
Vinko Vrsalovic
you should also accept just CR, because some older systems used just CR.
Brad Gilbert
No, you should be fairly strict in what you accept and very strict in what you emit. This cuts down on unexpected errors where something tries to guess what some possible ambiguity means instead of just rejecting it.
staticsan
staticsan - 27 years worth of internet protocols disagree with you. See RFC793.
Alnitak
+2  A: 

This is not a language compatibility issue, but either a file issue or a protocol issue. File-wise: Unix uses \n as a carriage return, Windows uses \r\n and I think MacOS used (not sure about now) \r. Many 'cross platform' languages abstract this in a platform dependant variable. Protocol-wise: what the protocol specifies.

Vinko Vrsalovic
The current Macintosh OS (OS X) is Unix, and uses newline ('\n') as the line separator.CP-M/MS-DOS/Windows use \r\n because early character-mode printers required one control char to move the print head to the left margin (\r) and one to advance the paper by one line (\n).
joel.neely