Sign in

Scratching the surface of JS++

The problems

Dynamic typing is great! It is basically the function overloading of Javascript. You can define APIs that allow users to use your module as they’d like. You can switch between passing a string for some default behavior or a complex configuration object if you need to set things up in detail. But there’s also a catch. Take a look at the following case from Lodash:

The concept

JS++ is a superset of Javascript, which allows for a more strict handling of types, to ensure fewer runtime errors. It implements runtime type conversions for the built-in data types, and also creates a barrier between the code you’ve written in JS++ and the outside. Because it’s a superset, your plain Javascript is still valid!

The syntax

The first thing that grabbed my attention when I landed on Onux’s website was the syntax of JS++. Familiar, simple, readable. Is this really Javascript? This is the question I asked myself. Although the site went through an update since then, it still welcomes you with a snippet of code which doesn’t look like Javascript initially until you read it through.

Typescript vs JS++ syntax defining variables.
Feels clean

In a nutshell: the colon syntax is easier for the compiler writers and harder for the developers, and the traditional C syntax is harder for the compiler writers and easier for the developers. ~Roger Poon

I recommend you to read the full article on the challenges of writing a compiler that makes syntax like this possible for Javascript:

Final thoughts

I’m very much in favor of this endeavor! It’s safer, which is a concern in production. It’s cleaner, as it allows more freedom on coding style, allowing you to write less and achieve more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store