mapsapi-codestyle icon indicating copy to clipboard operation
mapsapi-codestyle copied to clipboard

LF at the End of File

Open twirl opened this issue 11 years ago • 49 comments

Why using this rule in 2014? Are you still making one large js file with cat?

twirl avatar Dec 25 '14 10:12 twirl

First of all, a whole bunch of unix utils rely upon the fact that every line in a text file ends with newline. Second, some editors inserts last newline automatically, so you may accidentally become author of the last line. This rule has the very same meaning as not BOM rule, UTF8 as an encoding and prohibition of trailing whitespaces: keep project files in a uniform and most portable way.

dmikis avatar Dec 25 '14 11:12 dmikis

What are those UNIX tools? If we say we need portability, then why LF not CR LF?

twirl avatar Dec 25 '14 12:12 twirl

What are those UNIX tools?

Mainly, editors: they just add last newline on saving a file (and you'll become the author of the last line). According to POSIX in Unix-like systems text file is the one with newlines at the end of every line, including last line. Otherwise a program has every right to treat a file as a binary one.

If we say we need portability, then why LF not CR LF?

CR LF is Win-only, whereas LF is for everything else we actually use. Majority wins.

dmikis avatar Dec 25 '14 12:12 dmikis

What's the problem with being an author of empty line? And why state this in a codestyle?

twirl avatar Dec 25 '14 13:12 twirl

Not empty but the last one, which can be meaningful.

dmikis avatar Dec 25 '14 13:12 dmikis

Meaningful to people? How?

twirl avatar Dec 25 '14 13:12 twirl

You know you can write code and the last line of a file? :)

dmikis avatar Dec 25 '14 13:12 dmikis

I don't understand.

twirl avatar Dec 25 '14 13:12 twirl

I don't want to argue about this anymore. There is an implication from POSIX, which may or may not be strictly necessary, and since we mostly use POSIX-compliant tools I suggest this rule continues to live. There is no any reason whatsoever to change this, only nasty little repercussions.

dmikis avatar Dec 25 '14 13:12 dmikis

We live without this rule, and everything is fine. Problem is greatly exaggerated, no contemporary tool gives any damn to absence of blank line.

twirl avatar Dec 26 '14 11:12 twirl

Again, what about ones adding the last newline?

dmikis avatar Dec 26 '14 12:12 dmikis

See no problem with them (== with being an author of blank line).

twirl avatar Dec 26 '14 12:12 twirl

It's not just that: you may accidentally commit files you haven't actually changed.

dmikis avatar Dec 26 '14 12:12 dmikis

Does this impose any problem?

twirl avatar Dec 26 '14 12:12 twirl

I believe it does. SCMs are not only for ability to revert some changes, they're also able to provide sometimes crucial info about a piece of code. Thus checking in unrelated crap is not exactly desired.

dmikis avatar Dec 26 '14 12:12 dmikis

git blame and svn blame provide information regarding every single line, so you wouldn't have problem with unrelated crap.

twirl avatar Dec 26 '14 12:12 twirl

You do understand that would be informational noise which would not ease an investigation.

dmikis avatar Dec 26 '14 12:12 dmikis

Requirement to add LFs to all files makes much more noise.

twirl avatar Dec 26 '14 13:12 twirl

No, it's not. One in a lifetime setting to your editor.

dmikis avatar Dec 26 '14 13:12 dmikis

Nope. As you mentioned, there are tons of different tools, some of them add LF, and some do not.

twirl avatar Dec 26 '14 13:12 twirl