0

Why do line ending differ from platform to platform? Even why is there term like line ending in programming?

I prefer saving my codes in Unix/Linux format, even if I'm on Windows. Am I missing anything by not saving it in Windows or MacOS format? How does line ending effect in coding.

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
  • That depends entirely on what you're going to do with the file. If the end users might want to, for example, open it in notepad, then using UNIX end of line format would be inconvenient for them. – Harry Johnston Aug 08 '12 at 02:08

2 Answers2

1

In the early days, when Typewriters were nearly the only way of getting output from a computer, CR and LF did different things. Unix started the tradition of using a single character to mark the end of a line, probably because it made their pipelining easier; their drivers could easily convert a single LF to CR/LF if need be. Linux is mostly a Unix clone so it keeps that convention. The others hold on to the CR/LF convention for historical reasons, even though it's not strictly necessary.

Some languages such as C, C++, and Python will let you specify the type of file when you open it, either binary or text. For text files a translation is performed so that a single LF is translated into the line ending convention required by the OS.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
0

Basically everyone wanted to be different when creating OS's - Un*x's started with LF, then VMS and DOS wanted CR/LF (like a typewriter) and of course MAC wanted to be different so they went for CR only.

They just wanted to make it harder to transfer between OS's so that you 'bought' into one

Added because of comment

Up to the programmer - if you need to support different line endings then you must code for them. eg you could create a #define for the line ending and then have this change depending on compile options

Adrian Cornish
  • 23,227
  • 13
  • 61
  • 77
  • 1
    and how does this effect when coding? – Santosh Kumar Aug 08 '12 at 01:11
  • It really wasn't a deliberate attempt to limit compatibility for nefarious reasons. At the time these decisions were made, nobody worried about compatibility, it simply wasn't an issue. – Harry Johnston Aug 08 '12 at 02:07
  • @HarryJohnston also a real possibility - but I am still not taking off my tin foil hat! ;-) – Adrian Cornish Aug 08 '12 at 02:08
  • @HarryJohnston is right - back when these decisions were made, the various OS were not really in competition with each other. – Mark Ransom Aug 08 '12 at 03:39
  • @MarkRansom since all were licensed and paid for at the time I disagree - but a total semantic - we could argue for many days offline :-) - it would not help the OP – Adrian Cornish Aug 08 '12 at 03:42
  • Actually, VMS originally didn't use a line terminator, it used a character count before each line. Later versions of VMS added STREAM_CR and STREAM_LF format options for compatibility with other OSes. – Gordon Davisson Aug 08 '12 at 07:35
  • Did you mean **practically** line endings doesn't matter so much? – Santosh Kumar Aug 08 '12 at 12:03