Mixing Programming Languages

January 22, 2008 at 12:45 am (Uncategorized) (, , )

It is thrilling how much a small amount of rest can do to clear you thoughts. About ninety minutes ago I left the CodeMash 2007 event weary and still unsure of my opinions on the topics I had exposed myself two over the two days. To be sure, I was most unsure, and have always been not quite sure, of the idea of “mashing” different languages together in an application. It seems to work well when making web page; forcing JavaScript to manipulate an originally HTML web page via the in-memory XML of the DOM, but that has not convinced me.

So, weary and waiting for my wife to arrive at the Kalahari, I decided to take a nap to kill the time. I drifted off for a while easily but then awoke. Since the situation had not changed much in that half of an hour, I decided to try and sleep some more. As I started again, for no particular reason, I began to shuffle through some of the occurrences in Leo Tolstoy’s War and Peace that I have been trudging through for weeks now. What was hi-lighted in my mind were the frequent passages and phrases in this book, which in its entirety has been translated from Russian into English, that skip to French and German. The foreword to the book explains that these flips of language have been left intentionally by the translator because they were digressions from the original Russian that the book was authored in. This may seem odd, but not so much to me. I have a degree in English literature and I saw this technique used often. Not only is it useful to intermittently switch to French, German, Italian, Latin or some other language in literature, authors love to recreate dialects of languages. Some rare, inventive authors even make up their own languages (the most famous of which, to CodeMashers, will be J. R. R. Tolkein).

I moved in and out of sleep with this revelation in my mind: it is not world-changing, unusual, or even striking that an author of reputable literature would mix two languages together. I well know from my study of the English language that it is not perfect. And neither is German, Latin, Swahili, the Queen’s English or any other spoken language. Each language has an amount of nuances that borders innumerable that makes it expressive in ways different from all other languages. An author of good literature pays attention to every word that he produces. Every word must contribute meaningfully to the whole such that the whole is not complete or correct without that specific word. I won’t digress here, but picking that word is not just based on a definition, it is a decision made by considering definition, connotation, sense, length, look, context, and the author’s general attitude towards the word. What is important here is that this decision is important and must be made for every word in a work of literature. If no word in the main language of the work, say English, is just right, the author will look to another language. If it is a French word that is right, then the French word is used.

After I had analyzed this about the mix of languages in War and Peace I then had my revelation that there is absolutely nothing wrong with mixing programming languages together. Programming languages are no different than natural languages. Each programming language has nuances that make it expressive in ways that other languages cannot be. This leads to a perfect justification for intermingling programming languages. If, when building an application in one language, say Java, you become stuck as to how to express a certain step, you might find that inserting a line of Ruby will fix the problem. This is a wonderful realization. There should be no competition between languages because we should just accept that all languages (probably) are equal but different. Mixing them together is the only way to achieve the perfect language, no language can achieve this singularly.

This idea is what I think the CodeMash coordinators intended, although maybe not to this extreme. .NET and Java programmers do not have to work in isolation and should not. They should strive to understand each other’s ways to find that there is probably an inter-locking of strengths and weaknesses in both tool sets that, if not compatible with each other, at least teach one another lessons that make both better. After years of skepticism a little rest and a great conference cleared this up entirely for me. I hope that this brief writing has helped you as well.

Permalink Leave a Comment

Even more than Polyglot programming.

January 22, 2008 at 12:29 am (Uncategorized) (, , )

I recently attended the second installment of the CodeMash conference in Sandusky, Ohio where one of the three great key note speakers was Neal Ford. Neal introduced the audience to the notion of Polyglot Programming. Polyglot Programming is just a phrase for something that we all do sometimes, but don’t always realize we are doing it; programming in more than one language within the same context.

Even though most programmers, especially of the web variety, are familiar with this notion it was important that Neal organized some thoughts and observations about it. I think that the same programmers who realize they commonly use, for example, HTML, XML, JavaScript, and Java all in a single JSP page, tend to try hard to keep those languages separate abstractly. A common JSP will be organized into clumps of the various languages so as to aid in understanding.

After hearing Neal’s speech it occurred to me that the separation of languages we force ourselves to do is really unnatural. Writers don’t do this with the written language because it is too restrictive. Historians and journalists will often freely mix philosophic prose with cold hard statistical facts for example. And, even more compelling, the best writers of literature will weave phrases of a foreign language poetically into their works for greater effect.

Although there are many more, my best example right now is the book War and Peace by Leo Tolstoy. In War and Peace Tolstoy frequently inserts words and phrases from French and German. This tactic is not the device of arrogance or pedantic, but an effort at being as expressive and effective in language as possible.

Tolstoy mixed languages because he understood that sometimes a language can express something more effectively, expressively, succinctly, etc… than other languages. And Tolstoy was not the only author to mix languages. Mixing languages that way is just another literary tool that a good author will use if necessary. To enrich this point consider that Tolstoy wrote War and Peace in Russian, with the mixed in French and German. I don’t know any Russian, so I read the version translated into English. Despite the translation of the Russian into English, the phrases that Tolstoy inserted from languages other than Russian were not translated to English! That’s important because it signals a definite importance for those pieces of the text.

I think there is tons more to chase after in this topic. We are not at the point in Software Engineering where we can so easily mix Ruby and Lisp and HTML like Tolstoy mixed Russian and French and German, but, we’re moving in that direction. The plethora of languages that now run on the JVM is a good start and I hope that trend continues.

Permalink Leave a Comment