There are lots of questions asking what the correct order of the carriage return and new line characters is on Windows (it's \r\n
) but I have not found any real explanation as to why this is the case.
\n
is the new line character, and \r
is carriage return. So, if you have \r
first, which returns the cursor to the beginning of the current line - and then \n
afterwards, wouldn't that logically insert the \n
at the beginning of the current line and just move the current line down one instead of creating a line after?
I mean I understand that when simply writing these to a file it doesn't really matter, but when parsing/reading and outputting the text, it seems backwards to me.
The order is a homage to the typewriter days.
Early mechanical printers were too slow to return the carriage in the time it took to process one character. Therefore the time spent sending the line feed was not wasted (often several more characters had to be sent to ensure the carriage return had happened before sending a printing character). This is why the carriage return was always sent first.