Onux JS++, an answer to JavaScript ‘brittle’ type safety?

JavaScript is a brittle programming language and one typo can bring down a server says Roger Poon, founder of London-based Onux Corp.

JavaScript focus: Microsoft, Facebook & Google

It’s true… type checking JavaScript is, in fact, currently one of the most important areas of computer science right now. It is an issue being worked on by Microsoft, Facebook and Google just to highlight how difficult and important it is.

There are six types in JavaScript: Object, Number, StringBooleanNull and Undefined.

The problem is with achieving 100% correctness in a world where 99% correctness is not good.

Onux has released JS++ as a ‘type-safe’ version of JavaScript. Poon says that the inspiration for the technology came from the fact that it’s very difficult to analyse JavaScript without actually executing code… and the code can execute differently across web browsers and platforms.

The JS++ type system is optional & sound

This notion of ‘sound’ means that if a developer chooses to declare types, the types are guaranteed to always be correct — at compile time and runtime. This gives developers confidence that one small change won’t break the application and they can incrementally improve the quality of their code.

Image source: https://echosteg.com/

Image source: https://echosteg.com/

JS++’s (currently patent-pending) solution involves ‘unifying’ all JavaScript types into a single type known as the ‘unified external type’. As stated, types in JavaScript are difficult to get correctly at compile time. From ‘host objects’ providing implementation-defined types (as legally permitted by ECMAScript, JavaScript’s official language standard) to buggy and inconsistent web browser implementations, there are hundreds of problems that have made simply adding types to JavaScript a difficult challenge.

“Unlike other efforts that pollute their type systems with JavaScript’s types, JS++ effectively isolates JavaScript,” Poon says.

Once JavaScript is isolated, JS++ will perform automatic safeguarding and conversions between JS++ types and JavaScript types.

“It’s ‘santizing’ the data so the types will always remain correct. Conversions are a very ‘lightweight’ mechanism because they only need to happen on variable declarations, assignments, and function calls. Thus, we get type safety without sacrificing the ability to build performance-sensitive applications,” he adds.

Most programming languages share the same primitive data types such as Booleans, strings, and various number types. Conversions in these cases are straightforward, but JS++ takes it further. In object-oriented programming, developers can often construct classes that can expand the types for a program to thousands of types.

How can data with unpredictable formats and structures be converted?

In this case, JS++ enables developers to define custom conversion rules.

Poon clarifies, “It’s easy to figure out how to convert Booleans and strings. We wanted JS++ to be easy and seamless so we provide built-in conversions for these primitive data types. However, with constructed types, the implementation for one StringArray class might be different from another, so we let the user specify exactly how she wants the data safeguarded and converted from JS++ to JavaScript and vise versa.”

JS++ has been released in open beta and is free to download.