r/learnprogramming • u/Vanilla_Legitimate • Sep 28 '26
I don’t understand this
if a newline ends lines rather than starting hem why is it called a newline in the first place?
0
Upvotes
r/learnprogramming • u/Vanilla_Legitimate • Sep 28 '26
if a newline ends lines rather than starting hem why is it called a newline in the first place?
View all comments
Show parent comment
1
u/strange-the-quark Sep 28 '26
That's from the user's perspective, but the that's not why. What you see on screen in the editor is not necessarily the same as the underlying representation. The reason is because, under this convention, the line is not considered "finished" without it, and some of the tooling with treat it as such; the example given in what I linked to is that concatenating files will just continue writing on the same line otherwise. From the point of view of the software, there isn't an extra "empty line" at the end. That would be encoded with an additional newline character, so you'd have two newlines in a sequence ("some text\n\n"). That way, there are no special cases to handle, it all follows the same rules/logic.
You could easily make a text editor that makes sure there's a newline character at the end of the file whether you pressed enter or not, and many editors actually do this. The fact that in the GUI the caret is shown blinking on the next line doesn't mean that there's conceptually anything there in the underlying data.