Live data from Hacker News

Ask HN: Should source files always end in a new line?

news.ycombinator.com

21–30 of 40 posts

Re: Ask HN: Should source files always end in a new line?

#21

This doesn't matter even remotely and it is the height of bike shedding to even have a discussion about it.

Ending text files with a newline makes a functional difference. For one, no more diff noise from `\ no newline at end of file` in various Git diff views.

Re: Ask HN: Should source files always end in a new line?

#22
OP must've got a PR about this blocking him from merging.

It's having me think about the way prs should be done on divisive topics.

On one hand you have this "guy" who thinks he's gods gift to programming demanding a new line be added to all 30 files you're adding to the project.

On the other hand that "guy" is you.

What then? In both cases.

Re: Ask HN: Should source files always end in a new line?

#24
Do you mean an empty line? (since, as others have pointed out, every line ends in a newline character, for most text editors).

I like having the extra line, it is a very minimal difference, but this way it is possible to copy the last line by copying "down" rather than copying "out" to the end of the line.

Re: Ask HN: Should source files always end in a new line?

#26

Do you mean an empty line? (since, as others have pointed out, every line ends in a newline character, for most text editors). I like having the extra line, it is a very minimal difference, but this way it is possible to copy the last line by copying "down" rather than copying "out" to the end of the line.

They do mean an end of line character (linefeed on Linux), not an empty line by itself (i.e. not something like `hello\n\n`).

> have pointed out, every line ends in a newline character, for most text editors).

My colleagues always add changes that end with that `\ No newline at end of file` diff for certain source files.

Re: Ask HN: Should source files always end in a new line?

#28
post #25

Doesn't matter. Pick one. Enforce it with a linter. Move on with your life.

Most importantly, pick a linter that can automatically fix it. I use pre-commit (https://pre-commit.com) for that. As a bonus, it supports other, language-specific linters.

Re: Ask HN: Should source files always end in a new line?

#29

OP must've got a PR about this blocking him from merging. It's having me think about the way prs should be done on divisive topics. On one hand you have this "guy" who thinks he's gods gift to programming demanding a new line be added to all 30 files you're adding to the project. On the other hand that "guy" is you. What then? In both cases.

"What" to do matters less than consistency (in most cases - if you have technical reasons to pick one or the other, do so). Use a linter that can auto-fix everything and enforce that.
Post reply on HN