To start things off I’m going to be very forthcoming: I do not like the idea of purposefully omitting semicolons – or other syntactic characters, for that matter. I have several reasons for this opinion:
- Your production (minified) code doesn’t shrink in size, so there are no speed benefits
- The semicolon is technically required; automatic semicolon insertion (ASI) is designed to save the butt of an unaware developer
- Raise the possibility for buggy code just so you can save typing a character every so often
- Syntax helps developers see intention
My first point is on the lack of benefits gained from the practice of omitting semicolons. You might save some bytes in your production code, but that’s not what matters. If you’re using it on a finished product you should be using the minified code, which is unaffected by your lack of semicolon usage. A smart minifier will have ASI built into it so that you will have the semicolons you need in the minified code, so either way the semicolons are there. Besides the lack of speed gained in the minified code, if you did use the code without the semicolons in production code, it’s slightly slower because the compiler has to determine your intention and insert the proper semicolons for you.
As stated in the bullet points, ASI is not an excuse to be lazy and omit semicolons on purpose. ASI is designed to prevent errors in otherwise inerrant code and should not be abused for the sake of making your code look better (and it doesn’t really look any better anyway). Semicolons were included as syntax in order to delimit statements, so use them.
By deciding to omit semicolons, you must learn additional rules to follow in your program, and that learning time (and space in your brain) could be put to better use learning the rest of the language better. If you omit a semicolon where one needs to exist in order to prevent a parsing error, then you waste time having to go back and add it in. You spend too much time making sure that you can skip the semicolon, which pulls your mind away from what’s truly important: the program itself.
Syntax is Your Friend
Syntax is there to help people and parsers determine your intentions. When omitting a semicolon, the reader of your code may have to spend time they otherwise wouldn’t spend determining whether a line break is entirely for aesthetic reasons or as a delimiter between statements. Be a pal and use the proper syntax please.
Bringing this Fiasco to a Finish
As a final note and announcement: The contest to win a $299 Wijmo license is still ongoing. The contest ends May 8th, so make sure you sign up before then.