Polyglot Programs strikes me as pretty confusing and error prone. Right away I don't see any use to it besides "showing-off". Wouldn't that be a bad programming pattern, since it's not modular?

Is there something that can be implemented with it that's cleaner than designing software applications as suites of independently deployable modules/libraries/services?

  • 3
    These are for fun, and not about problem solving, there is no need for modularity, readability or robustness.
    – Basilevs
    Nov 28 '16 at 1:53
  • 3
    "Showing off" is specifically what these are about. Same as with JAPH programs and palindrome programs, code golf, etc. Nov 28 '16 at 2:22
  • 2
    Don't see any use... Well you could argue that it's an effective form of source obfuscation since now it's equally confusing to read in multiple languages. Nov 28 '16 at 2:59
  • There is another definition this is perhaps more relevant than the one in Wikipedia.
    – kdgregory
    Nov 28 '16 at 14:32

There are a couple of rare edge cases where polyglot programming comes in handy. With polyglot programming, the source code can be understood by multiple languages. Usually, this is done for some kind of backwards-compatibility.

For example, we can create a Perl script that can also be invoked as a shell script, which has some uses if the system doesn't support the shebang line properly:

#! -*-perl-*-
eval 'exec perl -x -wS $0 ${1+"$@"}'
    if 0;

(from perldoc perlrun)

It is also somewhat common for C++ libraries to express the externally-visible interface in a C-compatible manner. This allows the library to be used more easily. While C and C++ have similar syntax (and C++ was based on C), they differ in a couple of subtle points that can make it difficult to use C++ code from C.

Within C and C++, there's also a lot of clever use of the preprocessor to use compiler-specific features portably. If we argue that GCC's C is a different language from Visual Studio's C, a program that compiles under both could be considered to be polyglot.

Other than that, polyglot programming in production is pointless. You know what compiler or interpreter you'll be using, so you only have to target that.


Polyglot Programming is a very useful skill, even essential in nowadays computing environment. It is pretty much impossible to develop any non-toy software system in just one language.

For example, in a typical web application, you might use HTML, CSS, ECMAScript, TypeScript, Liquid, SQL, Java, sh, and Ant.

Polyglot Programming is about recursively breaking down a large problem into atomic sub-problems, and choosing the best language to solve each subproblem. The next step on the ladder would then be Language-Oriented Programming, which is about recursively breaking down a large problem into atomic sub-problems, and designing (and implementing) the ideal language to solve each subproblem.

  • 1
    The concept of "Polyglot Programming" you seem to be thinking of is not the same the OP linked in his question. I'd make that clear in the answer, at least
    – Iker
    Nov 28 '16 at 11:55
  • As far as I know, there is only one concept called "Polyglot Programming". I admit I didn't look at the link. Anyway, questions should be understandable without using external resources, so if the OP has some non-standard definition of "Polyglot Programming" in mind, he should specify it in the question. Nov 28 '16 at 11:58
  • 1
    The definition the OP uses is the only one I know about. Your answer doesn't address is.
    – Mat
    Nov 28 '16 at 12:31
  • @Mat: the page the OP linked to contains a scientific dissertation about different approaches to Polyglot Programming and their advantages and disadvantages from a business perspective. This dissertation also provides a definition of Polyglot Programming, and the very first sentence of that dissertation reads as follows: "Polyglot programming is the activity of using several programming languages in a software system." The very first Google hit for "Polyglot Programming" (at least for me, as we all know, in this day and age of personalized search that doesn't say much) is … Nov 28 '16 at 12:55
  • 2
    @JörgWMittag You have a point and you are, indeed, correct! It's not what the OP is talking about, however. The question is badly formed, now that I think about it.
    – T. Sar
    Nov 28 '16 at 12:59

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