Review of Transpilers [Part 2]

Schedule a Call

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.

Send Us a Message

Need expertise and innovation on your project? Our team can help.

    What are you looking to do?
    How did you hear about TechArk?

    * This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. By submitting this form, you agree that TechArk may send you promotional emails about our products and services. You can unsubscribe at any time, free of charge. View our Privacy Policy.

    Call Us