
Writing a triple polyglot script - nkanaev
https://nkanaev.github.io/posts/triple-polyglot/
======
GlitchMr
For something more ridiculous, feel free to check out this 281 language
Polyglot: [https://codegolf.stackexchange.com/questions/102370/add-a-
la...](https://codegolf.stackexchange.com/questions/102370/add-a-language-to-
a-polyglot?tab=Oldest)

~~~
jolmg
Direct link to the answer holding the 281 language one:

[https://codegolf.stackexchange.com/a/198810/71130](https://codegolf.stackexchange.com/a/198810/71130)

Each language was added by a distinct answer, each answer building on the work
of all the previous ones. The community teamwork in building such a
monstrosity is beautiful.

------
g3ol4d0
There was a CTF challenge a couple years back that we had to make a
Python/PHP/Node/Bash polyglot "quine". Here is my write up
[https://medium.com/@caioluders/polyglot-quine-
rctf-2018-cats...](https://medium.com/@caioluders/polyglot-quine-
rctf-2018-cats-rev-2-writeup-31953d131c9f)

------
jabbany
Ah, this reminds me of the time I encountered a polyglot "config file" in the
wild in a university autograding system.

Instead of being parsed, it was `import`-ed and `include`-d in Python code and
Makefiles. It had a `.py` extension so it took me a while to figure out why
everything was breaking when I added some Python code in it. All in all, a
very cursed setup.

~~~
foota
There's some production code at my work that relies on a file being parsable
in two languages

------
blunte
Languages with eval() kind of give you a pass on this challenge.

A more impressive alternative would be writing nested interpreters in multiple
languages... Or writing code which runs in one "language" and then self
modifies to another language which runs and subsequently self modifies, and so
on.

~~~
shoeffner
[https://github.com/mame/quine-relay](https://github.com/mame/quine-relay)

------
pjc50
There's a great history of polyglots. I saw this one published many years ago
in a magazine:
[https://gist.github.com/erickedji/92398](https://gist.github.com/erickedji/92398)

    
    
        CuG #%*   POLYGLOT - a program in eight languages      15 February 1991  *+Ex=

------
slumdev
I work hard to make sure that all of my Javascript is also valid Typescript.

------
somesortofsystm
If you love this, you're going to positively _squee_ at Poc||GTFO, if you
haven't read it yet:

[https://www.alchemistowl.org/pocorgtfo/](https://www.alchemistowl.org/pocorgtfo/)

I mean, does HN filter out PoC||GTFO release announcements or something? I
seem to remember there being mention that it might've hit the filter list ..

~~~
Cthulhu_
Nope, that exact link has been posted 22 times on HN:
[https://hn.algolia.com/?q=https%3A%2F%2Fwww.alchemistowl.org...](https://hn.algolia.com/?q=https%3A%2F%2Fwww.alchemistowl.org%2Fpocorgtfo%2F)

~~~
somesortofsystm
Haha, nice tool, good fu.

------
NinoScript
I’m not sure if I should triple his salary, or just fire him for creating that
monstrosity.

Haha, very cool though!

------
ptarjan
My favorite time I had to do this was for a real-life situation. I wanted a
script that was both a bash script (for speed) and a ruby script (if you
installed it the default way).

I came up with:
[https://github.com/sorbet/sorbet/blob/master/gems/sorbet/bin...](https://github.com/sorbet/sorbet/blob/master/gems/sorbet/bin/srb#L4)

------
unhammer
I actually had use for a polyglot script at work, since in .csproj files,
<PreBuildEvent> is run as a "batch" cmd script on Windows, but with bash on
Linux. The simplest trick I could find was this:

    
    
        rem () { ./bash-version.bash; exit $?; }
        rem skip rest of script if executed by bash
        rem batch script follows:
        IF %blah% EQU 0 etc.

------
Terretta
This is one of the vanishingly small implementations of fizz buzz posted
online that don’t have separate paths for fizzbuzz cases than for fizz and
buzz cases.

Usual solve is %3 = fizz, %5 = buzz, %15 = fizzbuzz ...

If you change 3 or 5, you now have to go edit 15 too, does that not seem like
a problem?

Nicely done.

------
bilekas
Ahaha I love this. Very clever idea too, "Triple-hirable" possibly, but I feel
your time is clearly better spent dreaming these nightmare concoctions!

