Review of Transpilers [Part 2]

IN NOVA FERT ANIMUS MUTATAS DICERE FORMAS
CORPORA; DI, COEPTIS (NAM VOS MUTASTIS ET ILLAS)
ADSPIRATE MEIS PRIMAQUE AB ORIGINE MUNDI
AD MEA PERPETUUM DEDUCITE TEMPORA CARMEN!

I want to speak about bodies changed into new forms.
You, gods, since you are the ones who alter these, and all other things,
inspire my attempt, and spin out a continuous thread of words,
from the world’s first origins to my own time.

Metamorphoses” by Ovid

Transpilation is the process of compiling source code written in one language to generate source code for a desired target language. With the ubiquity of JavaScript used not only in almost all modern web browsers but also in a growing number of server-side applications, a new generation of transpilers that target the generation of ECMA-compliant JavaScript have emerged to provide developers with a robust set of tools to develop efficient and elegant source-to-source solutions.

The motivation behind the transpilation process is that it accelerates the use of next-generation language syntax and language features while helping to ensure that the adoption of the language features results in browser-compatible JavaScript that meets the functional goals of applications.

In Part 1 of this series, two example transpilers were reviewed: TypeScript and Fable. In this second article, Babel and Nim are reviewed.

Babel

Babel allows developers to write code utilizing modern features of JavaScript without worrying about browser compatibility. It does this by transforming code into the older ES5 standard (a since-revised standard on which JavaScript is based). It is updated with yearly modules, collected together in a master preset that contains all changes since ES5. This lets developers use such features as classes, arrow functions, multiline strings, destructuring, and generators/iterators.

The Babel website includes a page of basic examples, linked to a “Try it Out” page that shows how Babel transforms pieces of code.

Nim

Nim is a program language capable of compiling into C-family languages (C, C++, Objective-C) and JavaScript. Note that Javascript compilation is considered an experimental feature and is presented with a list of restrictions in the documentation. Nim allows performance-enhancing optimizations at the compilation level and is extensible through templates, macros, and external libraries. It has also performed relatively well in benchmark testing.

Here are a few links for further exploration of the Nim language:

  • Nim provides specific information and instructions for each of the backends to which it compiles.
  • A third party has developed a self-described “rudimentary” Read Evaluate Print Loop (REPL) for Nim on github to allow previewing post-compilation code in real-time.
  • Nim also includes a since-deprecated built-in REPL called “nim secret”, put out of use due to its inability to incorporate C’s stdlib.

Blogger Dennis Felsing has provided an excellent, feature-by-feature overview of Nim’s capabilities.

Babel vs. Nim: Who Rules the Web? Check out our latest technical blog to find out. Our software developers are totally geeking out rn.

Share this:

Subscribe

Read more about Technology

How Consumers are Navigating the Holiday Price Wars

Mobile showrooming, which refers to the practice of viewing an item at a physical store and then shopping for the best price online, is being viewed as a threat by brick and mortar locations. And indeed, on the surface, there does seem to be some basis for that fear. Based of the economy of scale... Read more »

Read More

Hindsight is 2017

It’s been a wild ride, but we’re excited to wave goodbye to 2017 and say hello to whatever the next year may bring.

Read More