Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Language forks bring new power to programming

Serdar Yegulalp | April 10, 2015
From Hack to Cython, inventive forks are pushing popular programming languages in new directions.

A compiled-down language: JavaScript and the rest
How do you fork a language without forking the language itself? Create a new language that compiles down to the old one. The original language's limitations, typically its syntax, can be kept at arm's length from the programmer.

JavaScript and its derivatives are the most prominent examples. Rather than fork JavaScript by changing the language and creating a new interpreter or compiler for it, the new languages that use JavaScript at their core simply compile down to JavaScript and run on the existing engines for that language. CoffeeScript, TypeScript, and many other languages work this way.

Why do this? For one, it's easier to leverage an existing language's tool chain than it is to write an entirely new one. In JavaScript's case, the speed of the existing compilers is a huge boon; even the overhead of mapping constructs in the new language to constructs in JavaScript isn't too burdensome.

JavaScript has even been used to fork itself, in a sense. Tools like Babel allow features from JavaScript 6 to be back-ported to version 5. This way, a programmer can make use of those future language features right now, while browser-level support is still being rolled (or ironed) out.

One possible downside of using a transpiled version of a language is how debugging works. In JavaScript's case, most transpilers will generate a source map that can be used to match the generated JavaScript to its original source. CoffeeScript, for instance, permits this. That said, this approach has limits -- for instance, there's no way (yet) to look up original variable names when debugging, as opposed to their transpiled equivalents.

Subsets and supersets: Python
A third kind of language variant is a subset, a reduced version of the language designed to accelerate performance or address specific issues. Mozilla's asm.js is one example of a subset of JavaScript into which C/C++ programs can be compiled. But the ever popular Python includes many subsets of its own.

Subsets of Python generally exist as a way to address Python performance -- a language with fewer features is easier to optimize. RPython, the language used by the PyPy Python implementation, is "a restricted subset of Python that is amenable to static analysis" and provides stricter controls over what type a variable can be at any given time. The resulting code can be optimized far more readily by the PyPy JIT compiler than by Python itself.

Just as there are subsets, there are also supersets -- versions of a language that tack on features to broaden what can be done with it. Cython, another Python derivative, adds ways to generate C code directly from Python code, allowing a programmer to accelerate a Python program's performance by way of C.

 

Previous Page  1  2  3  Next Page 

Sign up for Computerworld eNewsletters.