Live data from Hacker News

Deep learning to translate between programming languages

ai.facebook.com

71–80 of 81 posts

Re: Deep learning to translate between programming languages

#71
post #28

Earlier quoted context omitted.

> "undefined" corners but that's not because we don't understand them but because they are deliberately left open. Even they are precisely defined. Not sure what language you are referring to, because this statement is very vague, but it's worth pointing out that undefined behavior in the C/C++ sense is absolutely not precisely defined. If a program executes undefined behavior in either of these languages, the entire…

> it's worth pointing out that undefined behavior in the C/C++ sense is absolutely not precisely defined. I think OP means "it is precisely defined by the spec which actions result in undefined behaviour"

Yes. Thank you.

Re: Deep learning to translate between programming languages

#72

Cool magic trick but I fail to see anything useful coming out of it. I would not blindly rewrite code, rather see how it can be improved and maybe dig a bit in the existing functionality, clean it out, use the new language in my advantage... Also as a programmer your mental modal is completely out of sync, how do you work on such application suddenly now that its all in Python (coming from C++)? Or is this shipped to…

You would, but FB and some other companies are dealing with 20 years and millions of lines of code written by a small army of developers. If they decide to switch language and rebuild their services, just doing it manually will in all likelihood take longer and more people if they don't apply tricks like automatic conversion, because it takes more effort to rebuild than to build fresh due to multiple reasons.

[deleted]

Re: Deep learning to translate between programming languages

#73

Earlier quoted context omitted.

You would, but FB and some other companies are dealing with 20 years and millions of lines of code written by a small army of developers. If they decide to switch language and rebuild their services, just doing it manually will in all likelihood take longer and more people if they don't apply tricks like automatic conversion, because it takes more effort to rebuild than to build fresh due to multiple reasons.

But the options aren’t “manual” and “ai”. There is a third option of using classical static analysis and compiler techniques that have been around for decades to do transpilation and large scale refactors. There are entire companies already build around this.

There's also a fourth option: do nothing. Leave the existing services in the languages that they're written in rather than translating them into other languages and laboriously debugging the resulting code. If these services communicate through well-defined APIs, any new services, which can be built in new languages, can communicate with the legacy services.

It may be more cost effective to keep around some developers who know the old code base and the language it's written in.

Re: Deep learning to translate between programming languages

#74

I've been thinking of a pandoc-like tool to translate between languages, i.e. a transpiler. You would need to write down the most general abstract syntax tree (AST) that encompasses all supported languages' features, as well as a way to read languages into this AST, and write the AST into languages. The cool thing about pandoc is the ability to transform the AST between the read and write. In the context of a transpi…

For the read part I think this something what GraalVM already does https://www.graalvm.org/docs/reference-manual/polyglot/

Re: Deep learning to translate between programming languages

#75

Earlier quoted context omitted.

I've heard that LLVM uses neural networks to drive the register allocator. I don't know how well it works, but it's a pretty cool idea.

In the PGO category, there's also this recent proposal: http://lists.llvm.org/pipermail/llvm-dev/2020-April/140763.h... At compile-time only, people have also been using trained models to derive cost functions for sequences of instructions (as opposed to analytical models which become very difficult to derive these days given the complexity of modern CPU architectures)

This is interesting, as I have essentially given up on attempting to figure out which sequences are faster. Instead, I go for the approximations that fewer instructions equals faster, and registers are faster.

It's hard to even figure out if the scheduling algorithms that work well on the Pentium and PentiumPro are worthwhile for the x86-64.

Re: Deep learning to translate between programming languages

#76
post #16

This sounds more impressive than it is. I kept an auto-translation going for quite a while from C# to Go just by creating some bash scripts. These languages are so similar, that while not idiomatic, you can be up and running with quite few rules and some simplifications to the original code. While I believe this is a good arena for algorithms to provide solution, I'm sceptical that ML in its current incarnations is t…

How do you handle generics? Go doesn’t have them, right? C# has an open source compiler (Rosyln) with an API that exposes lot of information, so for advanced needs there is this road too.

It was just a bunch of sed. It wouldn't handle generics in a general manner, so was just a script to fill a specific need in the span of a period. What was "amazing" is how much of C# didn't need any translation into Go code, for core business logic. It was up and running within say 20-30 minutes, though needed a tweak now and then (sort of like modern-day "AI" ;).

Re: Deep learning to translate between programming languages

#77
post #37

Earlier quoted context omitted.

That seems like a lot of effort when Julia is both high-level and efficient already.

Ok but I have 3 million lines of Python code, so that doesn't help me. I'm not gonna spend a year or two writing everything in Julia.

I hear that you can use Python from Julia and vice versa. You could technically get started immediately and strangle the python away.

Re: Deep learning to translate between programming languages

#78
post #16

This sounds more impressive than it is. I kept an auto-translation going for quite a while from C# to Go just by creating some bash scripts. These languages are so similar, that while not idiomatic, you can be up and running with quite few rules and some simplifications to the original code. While I believe this is a good arena for algorithms to provide solution, I'm sceptical that ML in its current incarnations is t…

An ML method is able to outperform hard-coded translators by large margins, supporting a wide mix of languages like Python → C++ and translation between varied native APIs, but it's not impressive impressive because you can do the same thing with `sed`?

Maybe take a look at the translations in the paper and come back to give a second opinion?

Re: Deep learning to translate between programming languages

#79
post #37

Earlier quoted context omitted.

That seems like a lot of effort when Julia is both high-level and efficient already.

Ok but I have 3 million lines of Python code, so that doesn't help me. I'm not gonna spend a year or two writing everything in Julia.

Good thing you don't have to: https://github.com/JuliaPy/PyCall.jl

Re: Deep learning to translate between programming languages

#80
post #38
post #37

Earlier quoted context omitted.

That seems like a lot of effort when Julia is both high-level and efficient already.

Let's rewrite everything in Julia.

There's no need to rewrite anything: https://github.com/JuliaPy/PyCall.jl

But yeah, I won't start any new projects in Python.

Post reply on HN