Imagine you have implemented the creation of a nice path-based star shape in Lisp. Then you discover Processing and you re-implement the whole code, because Processing/Java/Java2D is different. Then you want to tinker with libcinder, so you port your code to C++/Cairo.

You are (re)writing a lot of boiler plate code, while the actual requirement "create a star shape" (or "create a path, moveto x y, lineto x y") has not changed.

What are the options to encapsulate those implementation details? Some sort of pragmatic meta-programming? Maybe an expert system? How would you define your core business logic as language-independent as possible?

EDIT: This has been a real business problem for some people, if you look at Schlep or Stella. The idea is that you've written your core library e.g. in Java and now need to write an iOS app. On what language do you bet you future? How can you save your investment in your current code base?

  • 3
    To me this sounds more like playing around and exploring different languages. Which is entirely fine. Just IMHO "playing around in a pragmatic way" is an oxymoron. Mar 2, 2011 at 17:43
  • I suspect that it should be possible to compile SVG into almost any language/toolkit.
    – SK-logic
    Mar 2, 2011 at 18:18
  • @Péter Török: Think more of another example: you've written your core library in Java and now need to write an iOS app. Now what? This has been a real business problem for some people, if you look at people.csail.mit.edu/jaffer/Schlep or isi.edu/isd/LOOM/Stella. On what language do you bet you future? Mar 3, 2011 at 8:19
  • @Lenny222, sure it can be a real business problem. You just didn't present it that way. Btw I bet my future on my ability to learn new stuff and use whatever I have at my disposal to solve problems, not on any specific language. Mar 3, 2011 at 8:24
  • @Péter Török: Maybe, the problem has many facets to me. Since code is an investment, it would be a pitty to throw both a pile of source code and the contained logic away, if you 're moving to another language/platform. Mar 3, 2011 at 8:27

6 Answers 6


The only way to have language independence would be to create your own language. That's what Joel did with Wasabi. You'd essentially need a source-to-source compiler.

  • You create a DSL, and then write interpreters/compilers for it to each platform you find interesting. Mar 4, 2011 at 20:55

One approach is Program Transformation. This includes techniques that allow source-to-source translation. In theory, you write your program in one language and then transform it to other target languages. In practice, it's a lot of work and an area of high academic interest. Sample tools:

I don't want to give you false hope. You'd have to write the transformations yourself which is a lot of work. Still, people amaze me every day. Maybe you'll have an insight that makes program transformation much, much easier for everyone. It's a cool discipline that needs more cool participants.

  • 1
    The above tools are research tools, although Stratego and TXL are fairly robust. One big issue: you need parsers for the langauge(s) you want to transform. A real commercial tool: DMS Software Reengineering Toolkit; has parsers for many languages, and support for the kind of analyses you need to really do to transform code, which the academic ones do not have. See www.semanticdesigns.com/Products/DMS/DMSToolkit.html. (My company's product).
    – Ira Baxter
    Aug 31, 2011 at 5:09

Typically projects are much more complicated than your example so the proportion of boiler plate code is smaller. However core business logic can't be full extracted from the code. There are some things you can do like moving some rules to configuration files and databases, but at some point you will have to write code.

I would not be concerned about making a system language independent. Instead I would focus on a quality implementation in whatever language was selected for the task. Having clear well written code with supporting documentation for the project with be your best resource if you have to port the application to a new language.

Lastly, proof of concepts and prototypes should be built ahead of time so that your language choice doesn't change halfway through the project.

  1. For an "exploring different languages" type of szenario: Use a mind mapping tool as an improvement over hand written/painted notes
  2. For more structure: UML

The pragmatic way IMO would be to have a set of Lisp macros that would emit the destination language you wanted.


Have that problem with a custom library.

Try to use global concepts, that apply to several programming languages, and make documentation for that. If a concept exist in your original programming language, but not in the second, find an alternative concept.

Do a (U.M.L.) design of your (original and first programming language) source code, just as it is, without removing current bugs, without adding enhacements, just the way the code is.

By design, I mean, document your namespaces, classes, global functions, variables, etc.

Then, make a new version of your design, by copying original. Try to migrate your first language source code to the second programming language source code. (Example: C++, Java)

If you have to make changes to the new source code like new classes or new methods, you may have to document that, and modify the source code with the first programming language.

The following real world example worths reading, maybe not applying.

Example: My first programming language (Dephi) source code, uses properties. In my second programming language (C++) source code, properties doesn't exist.

I have documented in a U.M.L. that my clases have properties.

I change my second programming language (C++) source code, add new virtual methods ("getProperty", "setProperty"), that allow me to emulate properties.

Update the Documentation, so the new virtual methods are included. Update the first programming language, so it includes the new virtual methods.

Then, I migrate to a third programming language (C#). Wait. I use global libraries with global variables and global methods. C# doesn't have that concepts. But, I can use static classes or the singleton pattern.

I emulate the libraries with the singleton pattern. And it can be done, in the previous languages. So I document the changes, and replace the libraries code, in the first and second languages with the singleton pattern.

Now, my code works in 3 similar, but not equal languages. The documentation helps me makes changes, add enhacement, fix bugs on all of them.

Repeat the process, with other programming languages.

It's complicated, but it's done in the real world.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.