Lately, one of my pet peeves is seeing files that aren’t terminated with a newline. It’s part of our coding standards for Calypso at Automattic and it’s configured into our editors. But, I never knew why until recently.
If you’re curious yourself, check out this StackOverflow article.
I assume everyone here is familiar with the adage that all text files should end with a newline. I’ve known of this “rule” for years but I’ve always wondered — why?
Because that’s how the POSIX standard defines a line:
A sequence of zero or more non- characters plus a terminating character.
Therefore, lines not ending in a newline character aren’t considered actual lines. That’s why some programs have problems processing the last line of a file if it isn’t newline terminated.
Leave a Reply