Transcompilers and Interlinguistic Diplomacy

One of the most frequent questions asked by initiates into the profession is What language should I learn? This post…is not about that. Rather, it’s about transcompilers.

tl;dr – Why does this matter?

What is a transcompiler?

First, what is a regular compiler? A traditional compiler translates from a higher level of abstraction (e.g., Objective-C) to a lower level of abstraction (e.g., assembly or machine language). If a regular compiler can be thought of as ‘vertical’ translation, a transcompiler would be horizontal translation: it translates code from one language to another language of the same level of abstraction.

Screen Shot 2015-07-06 at 9.16.44 AM

It is very hard to write machine code directly. Humans overwhelmingly have some medium between us and the machine.
It is very hard to write machine code directly. Humans overwhelmingly have some medium between us and the machine.

One example is Coffeescript, a programming language that transcompiles into JavaScript, but has syntactic sugar inspired by Ruby among other languages. Wikipedia has a short and sweet example of how you can write something in one way, and have it compile natively as if it were written in a different way.

Where does Objective-C fit in?

Mostly, it doesn’t. This is because Objective-C has been developed more or less to support Apple devices, and the devices + language are more or less a one-to-one fit. However, often the tricky part of coding is not the UI, but the computations under the hood, aka business logic (I don’t only link to wikipedia, but I have found that, when it comes to All Things Code, it often is short, sweet, and to the point in an accessible way). Enter j2objc.

J2objC: Google’s Solution to a Shared Problem

J2objc is a script-based translator that converts Java source code into Objective-C source for iPhone/iPad applications. It is not an emulator, but outputs source code that can be built by XCode or Make, so the resulting apps run natively. My next post will be a non-methodical summary and highlight of descriptions I have found in the docs, and from a presentation (here) by the head of the project, Google’s Tom Ball. I have also been playing around with the tool, and will report any successes I have had. And if the gods smile on my efforts, I just may include a tutorial.

J2objC is not a cross-platform application tool. The source-code is compiled into object files, then linked up into an app. Your iOS device is running pure Objective-C. I will

tl;dr – Why does this matter?

This tool allows you to plug Java files into your Objective-C project. Java is still the #1 most popular programming language (by some metrics, at least), so collaboration can be made more easily. Java is also used for Android app development, and though it cannot be said that you could “write once, run anywhere”, it can automate much of the hassle of cross-development (e.g., the team at CodeName One, or these guys).