27 ms·
The fact that Windows uses CR-LF as a line separator baffles me to this day (and I am not old enough to have ever used or even seen a teletype terminal!) - for
by krylon 10y ago
The fact that Windows uses CR-LF as a line separator baffles me to this day (and I am not old enough to have ever used or even seen a teletype terminal!) - for a system that was developed on actual teletype terminals, it would have made perfect sense: To start a new line, you move the carriage back to the beginning of the line and advance the paper by one line.
But DOS was developed on/for systems with CRT displays.
It doesn't really bother me, but every now and then this strikes me as peculiar.
- wiredfool 10y agoAnd helpfully enough, EPS files can contain \r and \n as line feeds, singly or both, in either order.
- tonyedgecombe 10y agoI seem to remember the Acorn BBC used \n\r for line endings.
- vram22 10y agoRelated, Python has universal newlines support: https://www.google.com/search?q=python+universal+newlines+mode https://www.google.com/search?q=python+universal+newlines+mo... Edit: added the PEP (it's from 2002) and excerpt from it: https://www.python.org/dev/peps/pep-0278/ https://www.python.org/dev/peps/pep-0278/ This PEP discusses a way in which Python can support I/O on files which have a newline format that is not the native format on the platform, so that Python on each platform can read and import files with CR (Macintosh), LF (Unix) or CR LF (Windows) line endings.
- wiredfool 10y agoYeah, but it doesn't do \n \r, and iirc, it's not too happy when the line endings change midstream.
- vram22 10y agoInteresting, I had not checked it for those cases. Maybe it only reads a few lines at the start and assumes from the line endings for those, what it is going to be for the rest.
- prashnts 10y agoI think it's mainly to maintain backwards compatibility.
- krylon 10y agoThanks. That seems to be the reason for a lot of odd design choices. ;-)
- chadcmulligan 10y agohttp://stackoverflow.com/questions/6521685/why-does-windows-use-cr-lf http://stackoverflow.com/questions/6521685/why-does-windows-... has a good reason
- krylon 10y agoAaaah, yes, that makes sense. I remember setting up LPD on NetBSD years ago, and part of that was setting up a filter to prevent the staircase effect. Those were the days... ;-)
- chadcmulligan 10y agoand without the CR you could never have made the spinning line \|/-\|/-... :-)
- Piskvorrr 10y agoI call BS ;)
- torrent-of-ions 10y agoWhen you think about how a typewriter works it's actually correct. The "newline" handle does both a carriage return and a line feed. But you could conceivably do a carriage return without a line feed (and type over what you already have), or a line feed without a carriage return (which might have some actual use).
- Turing_Machine 10y agoOne use for CR without LF was to overstrike passwords on printing terminals. You'd enter your password (which would appear on the paper) then the system would go through several rounds of issuing a CR followed by overstriking the password with random characters.
- radarsat1 10y agoI still use CR without LF all the time. If I'm writing something that features a long loop, I might want status updates, so printf("%d \r", percentage); helps tremendously. You'll need to fflush(stdout) too, since usually flush is triggered by "\n". On the other hand, there are far fewer use cases for LF without CR, certainly nothing that isn't better done using ANSI codes.
- torrent-of-ions 10y agoThis the use of CR without LF on a virtual TTY. On a real TTY or typewriter there is less use, but as one user pointed out one could remove information like a password which was printed. LF without CR is something that one would do on a typewriter for typing tabulated data or mathematical formulae. It's just a way to go "down" but stay at the horizontal position you were previously at.
- JdeBP 10y agoIt's not just conceivable. It's how the output of grotty in TTY-37 mode works to this day. When you are reading a manual with underlining and boldface, and you haven't brought your manual system into the bold new GNU world of the 1990s where it actually uses ECMA-48 instead of TTY-37, the tty output driver is using carriage returns and backspaces to enact overstrikes. * http://jdebp.eu./Softwares/nosh/italics-in-manuals.html http://jdebp.eu./Softwares/nosh/italics-in-manuals.html I wrote a better manual page for ul(1) that explains some of this. ul is basically a TTY-37 to your-terminal-type converter, and it implements a lot of the effects that one would see on a real teletype. Unfortunately, the old manual hasn't progressed much beyond the original 1970s one and doesn't explain a lot of the functionality that the program actually has. * http://jdebp.eu./Proposals/ul.1 http://jdebp.eu./Proposals/ul.1
- TeMPOraL 10y agoCR/LF always struck me as the logical choice. And according to the SO link posted by 'chadcmulligan, it turns out that pure LF separator is actually a Unix hack that somehow got later accepted as the Right Way...
- aap_ 10y agoIt is the right way. Different terminals require different line endings and abstracting that to a single new line character makes sense. The UNIX tty driver then translates that new line character to what is appropriate to start a new line on a given terminal. In most cases CRLF is enough but older devices also needed additional delays.
- tzs 10y agoIf you are going with the abstract and translate approach, wouldn't the right way be to abstract to RS?
- kps 10y agoIt wasn't a Unix invention; see https://en.wikipedia.org/wiki/Newline#History https://en.wikipedia.org/wiki/Newline#History (as posted by randcraw nearby); for confirmation of the story there, see the Euro version of the standard for free at https://www.ecma-international.org/publications/standards/Ecma-006-arch.htm https://www.ecma-international.org/publications/standards/Ec...
- FreeFull 10y agoAn interesting thing to note is that if you put a unix terminal into raw mode, you also have to use both CR and LF, because LF only moves the cursor down, but doesn't move it to the start of the line.
- zb 10y agoThe thing to remember is that the CRs are never really gone, they're just silently inserted for you by the tty. Dealing with raw vs cooked (where LF is automatically translated to CRLF) ttys in UNIX is also a giant pain when you have to do it, so in a way it's not surprising that they decided to leave that out. The original DOS kernel was very minimal compared to UNIX even of the same era. Of course, it turns out that having to write CRLF into files is also a pain - Windows has binary and text mode files instead of raw and cooked mode ttys - and one that you encounter much more often.
- paulajohnson 10y agoAIUI is just that DOS was complying with the standard, while Unix had decided to break it. The standard was designed for physical teletypes and has a bunch of issues (like, what do you do with LF-CR?) but its not unreasonable of DOS to have stayed with it.
- randcraw 10y agoApparently the LF vs CR+LF printer control code standard arose ~1965 as ASA (pre-ANSI). Neither Unix nor Microsoft created the standard, and of course ASCII didn't either. https://en.wikipedia.org/wiki/Newline https://en.wikipedia.org/wiki/Newline
- mark-r 10y agoWindows is backwards compatible with DOS. DOS was backwards compatible with CP/M. It wasn't at all uncommon to see CP/M used with a printer as the primary interface.