Polyglot Programming Motivation


Java came along in 1995, it was a welcome relief to C++ programmers tired of fighting with pointers, memory management, and other arcane plumbing. Java allowed them to just get work done”.

The designers of Java purposely made the Java language look and feel a lot like C++ just because for Java to succeed, it need to appeal to the current high priesthood of developers, those same C++ developers.


“In ten years, everyone will be programming in Smalltalk, no matter what they call it”. 
- Glenn Vanderburg

Backward compatibility no longer makes much sense. Java developers must learn some strange stuff that has nothing to do with getting real work done but rather with strange rituals. Think about this code:

public class HelloWorld { 
public static void main(String[] args) {
System.out.println("Hello, Wold");

Remember such a zero-based arrays, as distinction between primitives and objects. Java is rife with C++-inms and baggage that don’t help the productivity of modern developers, all that made sense in 1995.

Good Chance for Changes: separated language from platform

“Fortunately, the designers of Java made a brilliant decision when they built Java: they separated the language from the platform. That gives developers a “get out of jail free” card called polyglot programming”.

Developers can use specialized languages to solve specific problems, we now have hundreds of languages that run on the Java virtual machine and the .NET managed runtime. The idea of polyglot programming is different of use SQL to access databases, JavaScript to add interactivity to web pages. These examples are orthogonal to the JVM: they run outside the world of Java. And that causes big headaches. It is about leveraging languages that produce bytecode within the JVM, eliminating impedance mismatch. The other impediment to polyglot programming is the perception that you are changing languages. Always in the past, changing languages meant changing platforms, which has an obvious bad connotation to developers who don’t want rewrite all their libraries again. But the separation of the platform from language in both Java and C# means you no longer have to fight that battle. Polyglot Programming allow you to leverage all your existing assets but also use languages more suitable to the job at hand.


Reading Files the Groovy Way (full example)

def number=0
new File (args[0]).eachLine { line ->
println "$number: $line"

JRuby and isBlank (full example)

class String
def blank?
empty? || strip.empty?
class BlankTest < Test::Unit::TestCase
def test_blank
assert "".blank?
assert " ".blank?
assert nil.to_s.blank?
assert ! "x".blank?

Jaskell and Functional Programming (full example)

new SafeArray arr = {
length = len;
at i = if i < begin || i >= len then
throw $ ArrayIndexOutofBoundsExeception.new[i]
arr[begin + i];


The days of trying to cram solutions into a single language are disappearing. Because we have outstanding managed runtimes — Java and CLR — we should leverage with better tools. Polyglot programming allow you to mix and match solutions without discarding all the code you already have that does important work. Language development is exploding on these two proven platforms. As developers, you need to learn how to take advantage of this growth so you can write better code using tools more suited to the job.

Further Reading

Neal Ford, Meme Wrangler
The ThoughtWorks Anthology: Polyglot Programming,
 Pragmatic Bookshelf, 2008
 Buy from Amazon

Like what you read? Give Daniel Negri a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.