Next; tech; meltdown..? Mandatory; semicolons; in; JavaScript; mulled;

Punctuation-averse devs, you're coding it wrong

By Thomas Claburn in San Francisco


In what non-technical people might take as an attempt to outdo the absurdity of the tabs vs. spaces debate that continues to divide programmers, the TC39 technical group that advises the development of ECMAScript – the specification from which JavaScript is implemented – has proposed telling web developers to terminate statements and declarations with semicolons.

Semicolons help separate JavaScript statements from one another.

A great many JavaScript developers already pepper their code with semicolons, but they often don't have to, even though semicolons are required in most cases by the ECMAScript specification.

That's because there's an out. "For convenience, however, such semicolons may be omitted from the source text in certain situations," the ECMAScript spec explains.

ECMAScript allows programmers, in most cases, to flout its punctuation requirement through a mechanism called Automatic Semicolon Insertion (ASI), which as its name suggests, automatically adds semicolon tokens to mark the end of code constructs when the source file gets parsed by a JavaScript engine.

This is done because programmers, aware that every additional character offers another chance to make an error, appreciate not being held to an exacting standard. It's something akin to a just-in-time spell-checker.

What's more, this laissez-faire approach makes JavaScript fairly forgiving, which in turn makes it more appealing to inexperienced programmers.

Linus Torvalds in sweary rant about punctuation in kernel comments


But there are situations where omitting a semicolon will cause errors or unexpected results, such as when defining JavaScript class fields, because the ASI mechanism gets confused. So encouraging greater use of semicolons would reduce the need to recognize those special cases where they can't be omitted.

Debates about the merits of ASI have been going on for years, and like the perennially unsettled conflict about whether source code should be indented using tabs or spaces, it remains a matter of disagreement.

Brendan Eich, the creator of JavaScript, expressed his disapproval via Twitter, noting that there are other means of enforcing code correctness and that a better approach would be avoiding risky grammar additions.

Were the proposal to be adopted, it would be of little immediate consequence. JavaScript developers could still ignore the recommendation and omit semicolons. ASI would still catch missing marks and add them; other syntax-checking tools known as linters would do the same.

"To be clear, we have no intention to deprecate or remove ASI," said Daniel Ehrenberg, a systems software engineer for Spain-based consultancy Igalia and a former member of Google's Linux kernel team, in an email to The Register.

As one of the co-authors of the proposal, Ehrenberg sees the recommendation as a way to ward off future problems arising from the growing complexity of ECMAScript.

The proposed wording says, "As new syntactic features are added to ECMAScript, additional cases requiring explicit semicolons emerge over time. As such, consistently explicit semicolon use is recommended."

The intention here is to discourage reliance on ASI because there are situations where it may not be reliable and there are likely to be more such situations as ECMAScript evolves.

Nonetheless, the proposal, which has yet to be accepted as part of the ECMAScript standard, has detractors. In the Github comments on the proposal – a pull request – Berlin-based developer Yoshua Wuyts laments, "This makes me a little sad. JS is the only language I write, and I don't use semicolons. I know it's just a warning clause, but it sounds like the TC39 is saying we're bad for using the language in a particular way. And it, feels, well, a little hurtful." ®

Sign up to our NewsletterGet IT in your inbox daily


More from The Register

The power JavaScript: 'Gandalf of JS' Wirfs-Brock on ECMAscript 2017

Looking to the AI future

JavaScript spec gets strung out on padding

ECMAScript 2017 addresses left-pad gate, alongside various improvements

Riddle me this: TypeScript's latest data type is literally unknown

Version 3.0 improvements in Microsoft's lang also include pumped up tuples

Oracle demands dev tear down iOS app that has 'JavaScript' in its name

Ordinary folk may be confused by title, takedown demand suggests

Microsoft requests ChakraCore support in main Node.js repository

Only on Windows for now, but cross-platform is promised

Node.js releases version 6.0. Yes, yes, LTS

More module issue fixes still require()d

Node.js fork io.js hits version 1.0 – but don't call it production-ready

Server-side JavaScript runtime makes major version break

Improving JavaScript: Google throws AtScript into the mix

Better JavaScript ... even works with Microsoft's TypeScript

Node.js says all is forgiven, welcomes io.js fork back into the fold

Version 4.0.0 reunites code bases, adds features

Windows 10 build 10041: 99 bugs on the wall, fix a bug, add a feature, 114 bugs on the wall

Pics More Cortana, updated browser, still a race to summer