- No configuration. The easiest way to enforce consistent style in your project. Just drop it in.
- Catch style errors before they're submitted in PRs. Saves precious code review time by eliminating back-and-forth between maintainer and contributor."
Although it appears to have been in the works for about a year, it was just introduced on the coding forum site Hacker News today, where semicolons emerged as a big sticking point, judging from comments such as:
- Why do these people want to avoid semicolons at all costs? Even inconsistencies? Even potential bugs? Why?? I just don't get it.
- If there was an actual gain to leaving out the semicolons, I'd be onboard but the only gain here is someone's aesthetic pleasure and someone else's aesthetic displeasure.
- No semicolons, two space indentation, space after function name, single quotes for strings? There's no way this would fly with a majority of developers.
- The no semicolons and space after function name are really the weird things here.
- I started skimming the rules and was like "this all seems fine" and then noticed "no semicolons".
YOU'LL PRY THEM FROM MY COLD, DEAD HANDS FIRST.
- no semicolons = no deal.
- Downside [of adopting this style, which the commenter did] is that very few other authors are using it, so when you share code people are concerned about its format (no semicolons in particular).
- No semicolons? REALLY? We've already spoke about this, people.
Even earlier than that, Robert Nyman addressed the issue in a post that generated debate in comments that persisted for some four years. (His advice: "make sure to always put semicolons in your code, to avoid potential problems."
Eich himself addressed the issue in a 2012 post titled The Infernal Semicolon. "Most of the comments in this semicolons in JS exchange make me sad," it starts out.
From a quick perusal of the debate still underway on the Web, that seems to be in line with the general developer consensus on the matter.
Not that there aren't vocal supporters of doing away with semicolons, even in the aforementioned Hacker News post. "Everything will be fine if you don't use semicolons," read one comment. "My team and I haven't, for years now. It's really, really, truly honestly ok. I promise. (Only exception is for-loops)."
The creators (Feross Aboukhadijeh published the GitHub effort) of this new style effort echo that view and obviously anticipated the ensuing debate. The project rules specify: "No semicolons -– It's fine. Really!" (Note there are three different links in the preceding text, though it might look like just one.)
Here's what that governing body says in a section titled "Automatic Semicolon Insertion":
Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations."
There's a bunch more verbiage on the rules for Automatic Semicolon Insertion, but I didn't even try to decipher it as I don't speak ECMAScript-ese. If somebody wants to wade through that officious-sounding crap and provide me with a TL:DR, I'm all ears. (One sentence in this Automatic Semicolon Insertion "guidance" is 88 words long -- who writes this stuff?)
A GitHub project detailing ECMAScript 6 features provides more information in something more closely resembling English:
ECMAScript since its earliest days supported automatic semicolon inference/insertion, of course. But people coding ECMAScript 5 started it in an era where lots of tools (especially source code compressors) had problems when semicolons were left out from the source code. As a consequence, most ECMAScript 5 coders maintained the traditional coding style with semicolons as the syntactic sugar, although in most of the cases they are not necessary. But this era is gone today. Both ECMAScript 6 and all tools (including compressors) perfectly support automatic semicolon inference/insertion nowadays. As a consequence, ECMAScript 6 coders nowadays can get rid of nearly all semicolons and remove clutter from their source code.
I'm all for removing clutter, but I somehow can't see myself not using semicolons. They just seem to provide some structured stability or something in a language that's fast and loose enough as it is.
What about you? Weigh in here in the comments or drop me a line.
Posted by David Ramel on 04/28/2016 at 1:52 PM