
OneLang – A tool to help writing code in multiple languages at the same time - GordonS
https://ide.onelang.io
======
zbentley
Why not write one piece of code that is _simultaneously valid_ in ~12
languages?

[https://github.com/stephane-chazelas/misc-
scripts/blob/maste...](https://github.com/stephane-chazelas/misc-
scripts/blob/master/which_interpreter)

I know it takes advantage of some technicalities (end-of-input separators and
such), but it's still a remarkably impressive piece of engineering. I put that
up there with some really hairy quines ([https://github.com/mame/quine-
relay](https://github.com/mame/quine-relay)), except it can actually be
_useful_!

~~~
btilly
What are the 12 languages?

I already tried:

node perl python ruby bash tcsh

From the code it is obvious that DOS and php are on the list, but I don't
happen to have them.

What are the others?

~~~
zbentley
I'm counting different editions of POSIX-compliant shell languages (e.g.
ksh93, zsh, bash, [t]csh) as different, as well as massively different
editions of DOS (freeDOS, MSDOS).

Hence the approximating tilde on "~12". Reasonable minds may consider there to
be many fewer, or many more, compatible interpreters.

EDIT: There also appear to be multiple compatible JavaScript interpreters--
browser V8 (though not Node, oddly--it's detected as generic; I may send a PR
sometime), SpiderMonkey, and older IE. I'm no expert on JS runtimes, though,
so the differing results I'm observing may be due to something else.

~~~
Vinnl
You should add Whitespace [0] to that :)

[0]
[https://en.wikipedia.org/wiki/Whitespace_(programming_langua...](https://en.wikipedia.org/wiki/Whitespace_\(programming_language\))

------
rwx------
Went to github to see the project maturity and

"OneLang is the love child of @koczkatamas and it was not a planned child.
.... OneLang is six months old at the time of writing and it already speaks,
but don't expect any comfortable conversation with it yet. It cannot grow
without a loving family, and as a single dad I cannot take care of it alone.
It needs more mommies and daddies who can help raise it up."

~~~
ASalazarMX
Wow, sounds real mature.

~~~
koczkatamas
At least I am not lying... ;)

~~~
mathgladiator
indeed, I like your project. Negativity of the community can be discouraging.
I stopped a project of mine because of a combination of the negativity and
from the reality of having to hiring and train people to use my language.

Here is _some_ of the negativity I got:
[https://www.reddit.com/r/programming/comments/6ori0/kira_is_...](https://www.reddit.com/r/programming/comments/6ori0/kira_is_a_programming_language_that_compiles_to/)

What excites me about your project is the possibility to write core math or
business logic once and then expose to multiple environments.

~~~
Iv
/r/programming is one of the most pedantic forum I have ever seen but I also
see it as a place where programmers flee and shelter from the non-technical
bullshit and vent a bit.

If you submit anything there, be prepared for harsh criticism. There is some
real value in there, but encouragement and cheerings won't come from there.

~~~
ASalazarMX
In other words, r/Programming is like the r/RoastMe of programming. Take
everything with several grains of of salt.

------
BillinghamJ
It seems like a really strange choice for the "source" language to be JS - a
language without any real static typing capability (even with TS).

The most limited & basic kinds of static analysis are technically possible,
but why not just start with an entirely static language and translate from
that to dynamic languages? Would seem much simpler...

~~~
smt88
> _It seems like a really strange choice for the "source" language to be JS_

I can't speak for the author, but I can think of several reasons I might
choose JS:

1\. Almost everyone working on the web knows it, so not knowing the source
language won't be a roadblock right away.

2\. Precisely because of the issues you mentioned, JS is a lot easier to
translate with perfect (or close to perfect) fidelity. If the source were
something like Haskell, every translation would be very lossy.

3\. JS has no boilerplate, like setting up a class or something. You can just
type statements.

4\. OneLang itself is written in TS, which means working with JS as the source
might be easier than, say, C#.

~~~
yorwba
> 2\. Precisely because of the issues you mentioned, JS is a lot easier to
> translate with perfect (or close to perfect) fidelity. If the source were
> something like Haskell, every translation would be very lossy.

On the contrary, the fewer restrictions a language has, the more difficult it
becomes to translate it into languages with stricter requirements. If this
were built on JavaScript and not TypeScript, it couldn't even generate the
correct type annotations for the other languages that require them. I doubt
that this project is going to grow a Haskell backend anytime soon.

------
sametmax
It's fun but breaks very quickly. One simple line such as
"console.log(Math.random(10));" will fail.

Amusing anyhow.

Also: please make it python 3. It's been 13 years...

~~~
stochastic_monk
2008 to 2018 is 10 years last I checked.

~~~
sametmax
Alright, my aim is very off. But even 5 years would be enough don't you think
?

~~~
stochastic_monk
I think it’s certainly time to have switched. All important libraries have
migrated and Python 3.6’s dictionary is faster and more memory-efficient.

Python 2 is dead. Long live Python 3.

------
SlowRobotAhead
How to do one thing ok, and 10 things strangely.

~~~
Iv
My sex life in one sentence.

------
marknadal
@koczkatamas this is mindblowingly awesome! Keep it up and ignore the haters.

Question: Can it support plain JS -> other languages? Or does it have to be
TypeScript? How could plain JS support be added?

------
EtDybNuvCu
From
[https://github.com/koczkatamas/onelang/wiki/FAQ](https://github.com/koczkatamas/onelang/wiki/FAQ)
it is clear that this tool falls far short of actual polyglottery.

------
jdonaldson
For anyone interested in cross platform development, check out Haxe and its
testing process. Writing a target that passes those tests is like finishing
Dark Souls. The level of effort here is about on par with finishing the
character selection screen.

------
everdev
Programming language translation has to be on the horizon. The cost of
switching is currently too high.

I got into a project years ago with this ambition using an AST and allowing
each language to provide their own translation for each syntax element or
block of code.

It also had the unique benefit of being able to take larger blocks like a
function and allowing the translator to provide a full function in some native
programming language so that a login or Fibonacci function could have multiple
translations in the same language allowing the translation to evolve and adapt
to use the most efficient one as new translations were introduced.

------
mpweiher
Isn't it more an indication of how little substantial difference there is
between most mainstream languages?

~~~
ksherlock
You can write Typescript in any programming language.

~~~
koczkatamas
In the demo video
([https://youtu.be/Rwo6KJ_Pa9Q](https://youtu.be/Rwo6KJ_Pa9Q)) there is a part
where I am editing the same code in 4 languages (C#, TypeScript, Ruby and PHP)
simultaneously.

But yeah, generally only a limited subset of a language is supported. This is
the price of writing code targeting multiple language. That's why you cannot
(and probably won't be able to) convert existing code.

------
maruhan2
Hey I'm curious about your journey than the final result. I only skimmed
through the code, so I don't understand everything, but it seems that the list
of things it will identify is in the "yaml" files. Did you write out all of
them or was there a pre-existing database somewhere?

------
diyseguy
I have wanted this for such a long time. How can I make python the main typing
window instead of Typscript?

------
awwaiid
See also [http://cdent.org/](http://cdent.org/)

------
rqs
Rather, I think it's a good tool that could help people who already knew a
programming language to learn a new one.

------
ahauxuueei
How is this different to haxe? [https://haxe.org/](https://haxe.org/)

~~~
koczkatamas
I started to write a comparison page here, but missing a lot of important
aspects: [https://github.com/koczkatamas/onelang/wiki/OneLang-
vs.-Haxe...](https://github.com/koczkatamas/onelang/wiki/OneLang-vs.-Haxe-
comparison)

Tl;dr: you cannot use One in production now, but the grand plan is to make One
as hackable and flexible as I can.

So here is the plan:

\- the compiler does not contain any target language-specific part, you can
add a new language by creating a few hundred lines of template file (this
actually works already, it is not just a plan)

\- rewrite One in One, so you can convert from any language to any language in
any language

\- there is no StdLib, but libraries can be created by anyone. We publish
interface and implementation definition separately, and you can eg. implement
a Web client interface for PHP and Node, while somebody else can implement it
for C# and Swift. Behaviour defined by interface tests, if your implementation
passes interface test => good. If there is no test for an edge-case =>
undefined behaviour. Read more here:
[https://github.com/koczkatamas/onelang/issues/9](https://github.com/koczkatamas/onelang/issues/9)

\- you write a library in One and it helps you to publish to every language's
package manager (npm, pip, NuGet, etc). You can reach much more developer with
your library compared to targeting only one lang's developer base

~~~
ghthor
This idea has been ronning around in my head, paired with a mining and crypto
element.

The language specific implementations of those interfaces could be mined(by
hand or automated) for coins to directly incentivise engineering effort. The
block acceptance would be based on the universal tests/benchmarks passing.

------
lozzo
it does not work on my first test:

My program is i=1 and the Java program it produces is:

class Program { public static void main(String[] args) throws Exception { i =
1; } }

which is wrong because "i" must be defined in java as in "int i;"

~~~
yorwba
Try writing "let i = 1". I think the assumption is that if you use undeclared
identifiers, you'll provide them to the generated code in some other way.

------
tpetry
If anybody is looking for something stable for years, have a look at haxe [1]

[1] [https://haxe.org](https://haxe.org)

~~~
MikeTheGreat
Can I ask how Haxe is connected to Flash?

For some reason, the first time I looked at Haxe I got the impression that
Haxe is an open-source Flash / Flash successor. (Mostly, I think, because
Flash keeps getting mentioned with projects associated with Haxe, like OpenFL
and Flambe, and several times in the Haxe Wikipedia article).

Clearly Haxe isn't "just" an open Flash, but how is Haxe related to Flash?

~~~
sshine
Haxe can compile to Flash, which is such a distinguishing feature that people
actually use it to write Flash applets:

[https://haxe.org/manual/target-flash-getting-
started.html](https://haxe.org/manual/target-flash-getting-started.html)

If you have ever tried to write Flash applets the old-fashioned way, it feels
more like a scriptable paint program.

------
HasbroMurderer
Opening the site on my 3GB RAM laptop froze it - could you please not pile web
frameworks atop one another? Being able to translate between languages in all
cases is intrinsically impossible because of the halting problem; that this
works is a testament to how restrictive and bland the Von Neumann language
paradigm is, seeing as these languages aren't terribly different and all have
ridiculously long specs. The closest you could get to doing this for most
languages would be to specify sets of composable, first-class macros in a
purpose-written Lisp (almost certainly a Scheme derivative) and write FFIs to
port in standard libraries around the core languages made from macros.

~~~
yorwba
The halting problem has nothing to say against translating between languages.
A non-terminating program will simply be translated into another non-
terminating program. In fact, Turing completeness is all about the fact that a
program in any language can be translated into an equivalent program in
another.

Some languages can't be _parsed_ without solving the halting problem, but even
in such cases, you can simply bundle it with an interpreter in the target
language. And the subset of programs humans are actually likely to write
should be much saner.

