Why it's Better to Put a Line-break at the End of a file

03 Mar 2014

Why it's worth the effort?

Because in a lot of cases, we use some kind of concatenation programs to concat our code. Looking at these code separately, they are all fine, but sometimes... Look what will happen if the following two snippets get concatenated, note that there's no line break at the end of code1.js?

code1.js

//here is some comments on the end of the file

code2.js

/**
Some lic statement...
**/
... Some real code here

When they are concatenated, it becomes this

//here is some comments on the end of the file/**
Some lic statement...
**/
... Some real code here

The comment start symbol /** is commented out by the previous file, ORZ...

So, let's put a line-break at the end of a code file. Not because of GCC's quirky requirement, but for our own wellbeing, it can save you a lot of headaches.