Language Transformations and You: Transpiling

Hey everyone!

It’s time for our 4th and final post on Language Transformations, this time taking a look at transpiling. Transpiling is the process of taking one source language and transforming it into another source language. If it sounds a lot like compiling, that’s because for the most part, it is. The main difference between transpiling and compiling, however, is the output. Compiling generally takes source code and transforms it into a more machine interpretable set of instructions. Transpiling on the other hand, outputs another human readable and usable language.

So why use transpiling?

Getting Awesome New Features

I’m sure by now you have figured out that I love javascript and web development from my posts. 🙂

The unfortunate problem is that javascript is still in its adolescence. It has some great features, does some awesome things and has some powerful frameworks and libraries. That being said, it doesn’t have comprehensions, it’s weakly typed (a strength and a weakness) and it doesn’t handle text manipulation very well. It has a laundry list of problems….as well as a massive list of incredible solutions. Yet if I want some or even any of these issues to be natively resolved, I have to wait for browser support for ES6 and ES7.

Enter transpiling. With transpiling, you can get solutions for all of these problems, and even some problems you didn’t know existed, like gaining Tuples! You can use Coffeescript for text manipulation, value assertions and comprehensions or you can use TypeScript (or eventually AtScript) for value assertions and strongly typed scripts. It doesn’t stop with javascript; you can get variables, calculations and mixins by using Sass or Less in place of CSS. You can also get better readability and templating with Jade instead of HTML.

Generally, this is the main reason that transpiling comes about. Someone says “I wish X language did Y,” and then they build a transpiler.

Familiarity

Let’s face it. Most developers have a go-to language that they use for a good share of their projects. Of course, there are generalists, newer and better languages, and some projects that simply don’t allow you to use your favorite language. What transpiling can allow, then, is the use of language features and syntax from your favorite language that is transformed into the language that generalists, early adopters and projects love!

Take coffeescript for example. It types, looks and feels a lot like ruby and even python. It takes their strengths and applies them to javascript, giving you the familiarity of a more mature programming language. Suddenly your client code looks a lot like your server code and has quite a few more features. The best part is that you get some ES6 functionality by using Coffeescript, like arrow functions, comprehensions and string templating.

Keeping it DRY

DRY or as we all know it, Don’t Repeat Yourself, is a fundamental paradigm to software engineering. There may be situations where you need to have redundancy and repetition, but in most cases, keeping everything DRY is the best way to increase maintainability by reducing your points of maintenance (and failure). So then, how does DRY apply to transpiling?

Transpiling allows you to build your application in one language, and then port it to many different platforms. You can build websites and mobile apps at the same time with Phone Gap. Or you can build those same apps using C# with Xamarin. When you are done, these services will transpile your source code from one platform into a native language that your mobile devices can understand.

I know, I know, this post was a lot shorter and was not as rife with examples as my other Language Transformation posts. But here’s the best part about transpiling…it’s simple enough that I don’t have to talk on and on about it. If you need more features, familiarity or a single code base, then it is time to look into transpiling.

As for me and my development? I’m sticking with pure JS and macros. Call me a hypocrite, but I just love me some curly braces, polyfills and creating my own domain language. But hey…I’m a bit crazy.