CRLF is wrong???-VBForums
Results 1 to 20 of 20

Thread: CRLF is wrong???

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,202

    CRLF is wrong???

    I always knew that the CRLF came from Carriage Return and Line Feed from the days of the electronic typewriters ... but never really thought about it logically until today...

    In the days of electronic typewriters a Line Feed would be followed by a Carriage Return to move the line down and the return the carriage to the start of the line I have never seen a typewriter do it the other way around... so why is this reversed in computing?? ... even the enter character symbol ↵ implies that the Line Feed should be done first!...

    I even looked up YouTube videos to double check ... and sure enough the LineFeed is done first

    Any thoughts ?? ... Do people agree that logically it should be done the other way around (although I would be against that since I have been conditioned to do it the other way)??

    Kris

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,097

    Re: CRLF is wrong???

    Quote Originally Posted by i00 View Post
    I always knew that the CRLF came from Carriage Return and Line Feed from the days of the electronic typewriters
    Actually, it predates electronic typewriters and goes back to manual ones. A manual typewriter - at least, all the ones that I can remember - had a handle on the left side of the carriage that would turn the roller, i.e. perform a line feed. Once you had pushed the handle as far as it would go, because it was attached to the carriage, continuing to push would return the carriage to the starting position, i.e. perform a carriage return.

    It was a function of the mechanics of the machine that it was done that way so electronic typewriters presumably just mimicked that. In truth, if you're not doing it manually then it really doesn't matter which way around it's done. To do the carriage return first on a manual typewriter would have required significantly more resistance in that handle or significantly less in the carriage, which would be impractical. That would mean not being able to perform a line feed without a carriage return. As it was implemented, you could push the handle gently for just a line feed, push the carriage itself for a carriage return or push the handle firmly for both.

    I'm not sure why they are the way around that they are in Windows (presumably DOS beforehand) but it may just be that whoever made the decision just didn't think about it too hard because it really didn't matter. That said, there may have been some specific technical reason that I'm just not aware of. It is an interesting point though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,875

    Re: CRLF is wrong???

    I'm pretty sure that it dates back to Teletypes and related communications hardware, not typewriters. These codes go back at least to Baudot's 5-level "printing telegraph" code. Western Union probably first included CR and LF characters to support its devices of the early 20th Century.

    My recollection is that CR generally preceded LF because these devices had a moving printhead rather than a moving paper carriage, and carriage line feeding was more stable and interfered with the ribbon less when the head was not moving.

    NUL-padding was sometimes used to give the head time to move and stop before the LF character was sent.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,097

    Re: CRLF is wrong???

    Quote Originally Posted by dilettante View Post
    I'm pretty sure that it dates back to Teletypes and related communications hardware, not typewriters.
    Distinctly possible. I guess the typewriters were simply mimicking the machines that came before them and it was actually them that reversed the original order for the mechanical reason that I mentioned. DOS/Windows may actually be using the "correct" original order, demonstrating just how geeky the people working on it back then really were.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,050

    Re: CRLF is wrong???

    Quote Originally Posted by dilettante View Post
    ...
    My recollection is that CR generally preceded LF because these devices had a moving printhead rather than a moving paper carriage, and carriage line feeding was more stable and interfered with the ribbon less when the head was not moving.

    NUL-padding was sometimes used to give the head time to move and stop before the LF character was sent.
    I'm not sure there was a problem with the carriage rotating while the head was returning to the left.
    If you wanted to bold a line it was more efficient to send the CR and then repeat the line rather than send a backspace for every character. Of course if only a few characters needed to be bolded then it would backspace after the character and repeat the character.

    I think the carriage return tended to come first because the carriage return key was on the middle row, so was generally under you finger as you typed. Once the carriage return was entered and the head was returning, you could type the Line Feed key which was on the bottom row while it was making its way back and get your fingers back into position ready to continue typing. It was a two step process that just became sort of rote after having to do a lot of typing on a teletype.
    Also, as dilettante pointed out, when receiving codes, there were usually extra nulls sent after the carriage return in order to allow for the time needed to get the head back.
    Another reason that the carriage return probably ended up coming first is that you always needed to send a carriage return, but you didn't always necessarily want to do a line feed, so the line feed being optional would naturally seem to come second, as optional parameters usually do.

    One bit of evidence that someone spent too much time reading teletype printouts on systems where there was a tendency for some characters to get lost in transmission, was the fact that the Alt key was used to switch between alternate characters sets, i.e. the primary set of characters contained the uppercase letters and a few other characters (you only had 32 possible codes, and one of those was the Alt key code which toggle between the first set and the second). The second set had the numbers, and most of the punctuation.
    Sometimes the Alt key code would be lost in transmission, so the teletype would be printing numbers and punctuation when it should be printing letters, and vice versa. If you could still decode the messages when that happened, you know you've been working with it too long.

    Those were the days.

  6. #6
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    426

    Re: CRLF is wrong???

    On teletype terminals (ASR33 etc) and other manual output devices etc etc, CR could potentially take the most time to complete - depending upon where was the head - so it made sense to start that operation first. If the head hadn't quite moved to the left when the LF was received then this didn't matter too much as doing a LF whilst the head was moving was OK. However, if a LF was done before the CR then the head could still be moving to the left when the next char was received to print which could potentially be printed at not quite the left. Hence CR before LF.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,166

    Re: CRLF is wrong???

    I like that the reason we're concerned is "What if Windows didn't get compatibility with machines that predate computers right?" not "Why are there still multiple conflicting line ending patterns in 2017?"
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  8. #8
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    426

    Re: CRLF is wrong???

    Unless you're reading files as binary or doing other low-level stuff the ordering shouldn't be an issue as 'cooked' input should translate CRLF & LFCR to LF.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,115

    Re: CRLF is wrong???

    I like the fact that y'all can talk about it like you were there. Not JUST a bunch of geeks 'round these parts!
    My usual boring signature: Nothing

  10. #10
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    426

    Re: CRLF is wrong???

    like you were there
    Yeah, the memories - having to first load the Basic interpretor into memory from paper tape before being able to run a basic program also loaded from paper-tape... Getting the knack of splicing paper-tape and repairing it when it tears... and don't start me on trying to load a compiler and program via punched cards when the card-reader keeps jamming cause the corner of one card was a bit bent and having to start again... Getting to use an interactive electric teletype was a major advancement. You young'uns don't know what we pioneers endured!
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,875

    Re: CRLF is wrong???

    Well back in the day in my 3rd full-time job I supported a large network of old 5-level Teletypes.

    To keep network costs down there were usually 5 to 15 of them on the same multidrop circuit using a "stunt box" attachment to support "selective calling." There was no Public Internet or even packet-switched networks yet.

  12. #12
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    911

    Re: CRLF is wrong???

    2kaud -

    Did you first have to toggle in the bootstrap loader for the paper tape via the front panel switches?

  13. #13
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    426

    Re: CRLF is wrong???

    Sometimes, yes. The memory on one system was ferrite core which is non-volatile (kept its contents after power removed) so the loader should have been in memory when power was first applied. However probably due to 'memory corruption from faulty programs' it was sometimes corrupted and had to be re-entered via the panel switches. A laminated printed copy of the octal version of the loader was attached next to the panel. When moved to disc storage, again sometimes the boot loader had still to be entered from the panel switches to boot from the disc system. You got quite adept at manipulating the switches.

    For another computer, the 'peripheral station (line printer/card reader)' attached to the mainframe had some computing power which had to be 'programmed' in order for it to talk to the main computer. This program was on punched cards which had to be loaded into the station when powered on or when it stopped working - which seemed to be at least once a day!

    Of course when the punched cards wouldn't read.... or the paper tape tore...
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  14. #14
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,488

    Re: CRLF is wrong???

    Perhaps this will help "visualize" it for you. I have to say that I did indeed use a manual typewriter and it was a chore to use back then

    Then a bell sounds and you have to press the carriage return lever (7). This turns the paper up and moves the carriage back to the start of the next line.
    http://www.explainthatstuff.com/typewriter.html
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  15. #15
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,050

    Re: CRLF is wrong???

    I also used a manual typewriter.
    One of the options that our machine had was a selection knob where you could select the amount the carriage ratcheted up when you press the lever to return the carriage to the beginning of the next line. For instance, sometime you had a requirement to use double spaced lines on a page. You would turn the knob to the "2" position so it would move up two lines when you pushed the lever to return the carriage to the left side of the page. I think I still have a basic manual Smith and Corona typewriter somewhere in the house.

  16. #16
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,115

    Re: CRLF is wrong???

    I remember that line space lever. I started out typing on a manual.
    My usual boring signature: Nothing

  17. #17
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,488

    Re: CRLF is wrong???

    I remember pressing too many keys at once and having the levers getting all jammed together lol
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,875

    Re: CRLF is wrong???

    I still wondering why anybody thinks electric typewriters have anything to do with data transmission or reception. Most had no communications capability or even local storage whatsoever.

  19. #19
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,166

    Re: CRLF is wrong???

    Because in terms of computer history it's about as near to a modern developer as a teletype, which is to say "completely archaic". The line ending difference between plaforms costs a lot of money due to subtle bugs and it's something we will faithfully maintain even beyond when we don't use keyboards anymore so the concept of an "enter" or "return" key makes any sense.

    Speaking of which, that I can call it "return" at all is alluding to the mechanical typewriter.
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,875

    Re: CRLF is wrong???

    It is like the difference between a telephone and a tape recorder.

    But oh, I guess people don't know what either of those are anymore either so clearly they never existed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.