News for hackers. Stuff that matters.
Re:Transpiling between any programming languages (2019) by krcz on Sunday February 16, 2020 @07:56AM (#22341341)
While it seems that their transpiler supports just simple JSON-like expressions with support for constructors for non-native literals (like big integers) and I don't think it could generalize into arbitrary code translation, I still appreciate the work they've done. Transpilation between arbitrary high level languages is a very hard task and I doubt anyone can achieve good solution for that anytime soon.

I have a different solution in mind: designing a language specifically for transpilation, so that it could be used to generate high quality, readable code for various programming languages (I call it "idiomatic translation"). I've recently started exploring that topic as a part of Zygote project [1].

[1] https://github.com/krcz/zygote

Re:Transpiling between any programming languages (2019) by swsieber on Sunday February 16, 2020 @11:18AM (#22342190)
You should check out Haxe. - it compiles to 10 source level languages and a couple of VMs.

https://haxe.org/

Re:Transpiling between any programming languages (2019) by dkersten on Sunday February 16, 2020 @02:31PM (#22343316)
The targets Haxe compiles to are all rather similar (object oriented mutable-state imperative VM's). While that's cool and interesting, its far from any language. I imagine adapting it to compiling to something like Haskell may be less than straightforward, at least in a way that produces decent quality/performant Haskell code.
Re:Transpiling between any programming languages (2019) by krcz on Sunday February 16, 2020 @11:35AM (#22342288)
Thank you, Haxe definitely has its place on my list of things to check. What worries me however is that there are no examples of output code on their webpage.
Re:Transpiling between any programming languages (2019) by haxiomic on Sunday February 16, 2020 @05:53PM (#22344235)
The output is pretty slim, it's one of the reasons I prefer using haxe over TypeScript when targeting the web – haxe has better dead-code-elimination so output js tends to be smaller and include a greater level of optimisation – check out this example to see what I mean https://try.haxe.org/#4f46D
Re:Transpiling between any programming languages (2019) by swsieber on Sunday February 16, 2020 @11:47AM (#22342356)
True. I don't think the output will be particularly pretty, and it does assume the presence of its own stdlib. But hopefully it's still fun to see how exactly they do things under the hood.
Re:Transpiling between any programming languages (2019) by aikah on Sunday February 16, 2020 @04:54PM (#22343979)
The best solution is to make every language a compile target for a virtual machine or some CLR flavor.

Creating yet another "high level" language that compile to all other languages would mean designing something that is the least common denominator between all languages, which is OK for a language that is not supposed to be written by hand, AKA bytecode, it's not OK for a language developers are supposed to write.

Re:Transpiling between any programming languages (2019) by krcz on Sunday February 16, 2020 @05:23PM (#22344118)
But in order to make it work you would need all the programs to start using the CLR. It's all of nothing. And if one of languages stops being supported - e.g. not receiving bindings for new libraries - you need to rewrite whole codebase to something different. In case of the "high level" language you just need to transpile it to one of the supported languages and continue development in the output language.

> designing something that is the least common denominator between all languages

My vision is rather finding some patterns, higher abstractions in various languages: e.g. imperative loop summing squares of all odd elements is semantically similar to filter -> map -> fold functional chain. Building whole language on such patterns will definitely be hard, but I believe it is possible and worth pursuing.

Re:Transpiling between any programming languages (2019) by OJFord on Sunday February 16, 2020 @09:34AM (#22341693)
Is that so different? The natural next step is implementing the reverse, other languages to yours, and then suddenly yours is an intermediate language that can be used to go other lang to other lang.
Re:Transpiling between any programming languages (2019) by krcz on Sunday February 16, 2020 @11:14AM (#22342159)
That might not be easy, for the same reason you can easily transform vector graphics into raster one but not the other way around or output of decompilers doesn't look nice: you are losing information during the translation process. You can easily transpile TypeScript to JavaScript, but that's not true for the reverse process.
Re:Transpiling between any programming languages (2019) by ptx on Sunday February 16, 2020 @04:01PM (#22343732)
The reverse process should be easy! Since TypeScript is a superset of JavaScript, transpilation is an identity transform. :)