New compiler tackles JavaScript's weak typing

06.06.2016
Software vendor Onux tackles the issue of type safety in JavaScript with a language called JS++, or JavaScript++, which checks types at compile time as opposed to runtime.

The Onux JS++ compiler unifies types into a single type known as the unified external type system. By providing a sound type system, declared types (such as a string) will never be incorrect, enabling development of more-reliable applications, said Roger Poon, CEO at Onux and the creator of JS++.

JS++, now available as an early-access preview, compiles to JavaScript and is supported wherever JavaScript is supported, according to Poon. Error-checking at compile time makes JS++ similar to languages like Java.

The technology is not open source, and Poon says the company is seeking to patent it, primarily as a defensive mechanism because companies like Facebook (with Flow) and Google (with AtScript and SoundScript) are working on the same problem. Developers will not have to pay any royalties to use JS++, he said. Onux's business model, however, includes selling support services and add-on libraries for purposes like charting and graphing. The standard library will be available for free.

Poon doesn't believe the closed-source nature of JS++ will scare off developers. In fact, he says enterprise developers are pleased with JS++ because it solves a major pain point for them. "They've got millions of lines of JavaScript code, mostly legacy code," he said. "One of the major problems is type-checking."

JS++ is positioned as a rival to Microsoft's TypeScript, which Poon said has an "unsound" type system. JS++ is compliant with ECMAScript 3, an older version of the specification underlying JavaScript. Poon said most developers are either using ES3 or ES5.

JavaScript developer and educator Eric Elliott took issue with Onux's claims, saying he  has not seen empirical evidence that sound type systems lead to lower bug density. "In fact, there is some evidence that the additional overhead of a complex type system may lead to higher bug density," he said, pointing to a recent essay. "In other words, type correctness does not guarantee program correctness." Elliott instead advocates for test-driven development.

"I have not used JS++ but I have no reason to believe that the broader JavaScript community will embrace it," Elliott said. "Many projects before have promised better type safety for the Web platform, including Google's SoundScript, Google's Dart language, Google's Google Web Toolkit, Microsoft's TypeScript, Facebook's Flow, and my own rtype project."

(www.infoworld.com)

Paul Krill