A newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. A newline is used to signify the end of a line of text and the start of a new one.
History
In the mid-1800s, long before the advent of teleprinters and teletype machines, Morse code operators or telegraphists invented and used Morse code prosigns to encode white space text formatting in formal written text messages. In particular, the Morse prosign BT (mnemonic break text), represented by the concatenation of literal textual Morse codes "B" and "T" characters, sent without the normal inter-character spacing, is used in Morse code to encode and indicate a new line or new section in a formal text message. Later, in the age of modern teleprinters, standardized character set control codes were developed to aid in white space text formatting. ASCII was developed simultaneously by the International Organization for Standardization (ISO) and the American Standards Association (ASA), the latter being the predecessor organization to American National Standards Institute (ANSI). During the period of 1963 to 1968, the ISO draft standards supported the use of either carriage return plus line feed (CR+LF) or LF alone as a newline, while the ASA drafts supported only CR+LF. The sequence CR+LF was commonly used on many early computer systems that had adopted Teletype machines—typically a Teletype Model 33 ASR—as a console device, because this sequence was required to position those printers at the start of a new line. The separation of newline into two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in time to print the next character. Any character printed after a CR would often print as a smudge in the middle of the page while the print head was still moving the carriage back to the first position. "The solution was to make the newline two characters: CR to move the carriage to column one, and LF to move the paper up." In fact, it was often necessary to send extra padding characters—extraneous CRs or NULs—which are ignored but give the print head time to move to the left margin. Many early video displays also required multiple character times to scroll the display. On such systems, applications had to talk directly to the Teletype machine and follow its conventions since the concept of device drivers hiding such hardware details from the application was not yet well developed. Therefore, text was routinely composed to satisfy the needs of Teletype machines. Most minicomputer systems from DEC used this convention. CP/M also used it in order to print on the same terminals that minicomputers used. From there MS-DOS (1981) adopted CP/M's CR+LF in order to be compatible, and this convention was inherited by Microsoft's later Windows operating system. The Multics operating system began development in 1964 and used LF alone as its newline. Multics used a device driver to translate this character to whatever sequence a printer needed (including extra padding characters), and the single byte was more convenient for programming. What seems like a more obvious choice – CR – was not used, as CR provided the useful function of overprinting one line with another to create boldface, underscore and strikethrough effects. Perhaps more importantly, the use of LF alone as a line terminator had already been incorporated into drafts of the eventual ISO/IEC 646 standard. Unix followed the Multics practice, and later Unix-like systems followed Unix. This created conflicts between Windows and Unix-like operating systems, whereby files composed on one operating system could not be properly formatted or interpreted by another operating system (for example a UNIX shell script written in a Windows text editor like Notepad).
Representation Earlier history in Telegraphy and typewriters generally considered starting a new line a single action, and it would make sense to encode it as a single control character. However, the design of printing teletypes led to the idea of a newline being two actions, a carriage return CR and line feed LF. A CR by itself was useful to overprint the current line to make double-struck bold or underscores. A LF going straight down was mechanically simpler and could print some text faster if there was a working backspace. Requiring two characters to start a line did not waste any time as the mechanisms were slower than the time it took to send both of them (often extra "padding" characters had to be sent to be sure the carriage had reached the left before the next printing character). The CR was always sent first as it was the slow one. If software did not want to process the characters before sending them to a teletype, this meant that each newline had to be stored as the CR+LF pair or CRLF, on paper tape or in text files. Often the "padding" characters had to be stored as well. Making newline be a single character just like space is helpful for text processing and pattern matching, and made the files smaller. Some systems did require LF to go to the left edge and many terminals had a configuration option to allow this (though this broke too much software that relied on LF going straight down). Multics and thus Unix instead required processing, a LF sent to a terminal was replaced by the operating system with CRLF (or whatever the terminal needed including padding characters).
… excerpt ends here. Continue reading the full article.


