What's the reason for leaving an extra blank line at the end of a code file?

It is historical, relating to common bugs in command line utilities for text processing. There are many programs on a Unix system for processing text, and most of them work on a line by line basis. There may or may not be any common command line tools that misbehave when the last line does not end in a newline, but the phenomenon is historically common enough that other tools started warning about the situation.

Last I checked vim is actually incapable of saving a file that does not end in a newline, going so far as to add one whether you put it there or not.


AFAIK, it is good practice to have every line ended using newline character, because when the code is parsed, it can be read using one simple function, which will split file into lines according to those newline characters. Without blank line and therefore last line ended with newline, you would lose all characters on that line.