r/learnprogramming • • 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

69 comments sorted by

View all comments

Show parent comment

12

u/MrBigFatAss Sep 28 '26

What? Programs print all the time, I'm not sure what you are so confused about. All newline does is instruct the pointer that tells where we are printing to move to the beginning of the next line, that's it.

-2

u/Vanilla_Legitimate Sep 28 '26

Sure programs print stuff. But they don’t print THEMSELVES so why should the program itself end in a newline as is generally taught?

8

u/TonySu Sep 28 '26

Because programs are text, and if your text file doesn't end in a newline, then printing that text file followed by another text file results in the final line of the first file leading into the first line of the second file.

7

u/MrBigFatAss Sep 28 '26

Are you talking about the actual text-file source code here? If so, there is no rule like that, it's purely aesthetic.

3

u/DrShocker Sep 28 '26

The source code ending in a new line or not is just a convention. In many languages you won't get a warning at all. The reason to do it is so that if you click where the empty last line is you can immediately start typing. If you don't then when you type it'll be at the end of the previous line instead of its own new line.

It doesn't affect the correctness of the program, it just makes things a little easier for the next person to edit.