Live data from Hacker News

Deep learning to translate between programming languages

ai.facebook.com

21–30 of 81 posts

Re: Deep learning to translate between programming languages

#21

I think that while the current technology could do such a thing, the current data absolutely cannot. Think of the parallel with language translations. We have tons of books that are all painstakingly translated from language to another by talented translators who even try to persevere idioms of each language, television and other media as well. I don't think there are even any copies out there of a faithful language…

Note that this algorithm does not require translations as input. It takes large corpus of the languages of interest, models them and then find parallel between both models which are used as a crude basis for a model. They use it to train a better model and iterate.

This stems from earlier work on natural language translation (by the same team) and opens quitte a number of doors.

Re: Deep learning to translate between programming languages

#22

Earlier quoted context omitted.

Facebook as a company do not believe in ever rewriting large code bases. You can view lots of their open source/technical achievements as out growths of this belief: - 2004, write PHP as it's fastest for now - 2008: PHP is too slow, compile it to C++ - 2011: C++ is too slow, write a VM and compile to assesmbly - 2012: PHP's type system sucks, write a better typer in OCaml (Hack) - They have done much the same for Jav…

How well does that really work out? It seems like that would aggregate a lot of cruft, or are there ways around that?

I think the theory is a small subset of engineers can do work that speeds up the entire codebase for the rest of the engineers instead of spending time rewriting that entire code base and also retraining all of those engineers.

Re: Deep learning to translate between programming languages

#23
post #14
post #12

Even if it works, which I doubt, the maintenance question is more important than just porting. Porting is rarely done just because there is a new modern language. Writing a compiler/transcoder is likely easier and safer, guaranteed to work. I wonder what the deep learning would do with concurrent code and differences in the memory models of the languages. The part is rather hard for experts in both languages and conc…

It seems like you could maybe go through machine code as an intermediary?

But wouldn't that just be decompiling with extra steps?

Re: Deep learning to translate between programming languages

#24
I see this as a great way to speed up manual code translation from a language to another.

Something like DeepL [1] but for code, where you can select one of several possible translations to translate a section of the code, rewrite part of the translation and have the algorithm take them into account for the rest of the code and indicate some prefered translations.

You cannot replace a human translator but you can certainly make him much faster and automate the trivial bits.

[1]: https://www.deepl.com/translator

Re: Deep learning to translate between programming languages

#26
post #10

Cool idea...I would be more interested in auto-documentation tool based on this.

That'd be truly remarkable as in actual magic.

Take this rather simple example:

  PointList interpolate(PointList sample_points, OrderedRealNumberList points_to_interpolate);
This function can be auto-documented from its name and the names and types of its arguments alone. No ML required - simple pattern matching and LUTs will do. But then again, do you really need a detailed documentation in such case?

Where a documentation would actually be helpful are cases like this:

  SUBROUTINE PCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR)
A format commonly found in the FORTRAN code of numeric libraries. If the author(s) didn't document this, an AI wouldn't stand a chance to know what it does.

PCHFE is Piecewise Cubic-Hermite Function Evaluation of course [1] and the parameters aren't exactly self-explanatory either...

[1] http://www.netlib.org/slatec/pchip/pchfe.f

Re: Deep learning to translate between programming languages

#27
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…

And it's also a quite nonsensical use of ML technology, to be honest. Neural nets are good for problem domains with fuzzy definitions of right and wrong as you find them in the physical world out there. Is this a tiger or a rock? Is this food or poison? Should I walk around this pond or swim through it? That's what the human brain is good at handling and neural nets are trying to approximate that. Programming languag…

So why does it work better than the commercially available tools at the moment as claimed in the article?

Re: Deep learning to translate between programming languages

#28
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…

And it's also a quite nonsensical use of ML technology, to be honest. Neural nets are good for problem domains with fuzzy definitions of right and wrong as you find them in the physical world out there. Is this a tiger or a rock? Is this food or poison? Should I walk around this pond or swim through it? That's what the human brain is good at handling and neural nets are trying to approximate that. Programming languag…

> "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 program execution is meaningless, including the time "before" undefined behavior occurred. The standard leaves room for the implementation to do absolutely anything before or after that point. In practice, what actually happens is the crazy complex interactions of a slightly broken abstraction that will depend on memory layout, optimizations, libraries, execution history, the phase of the moon, etc.

All that said, this isn't hard because undefined behavior. This is hard because languages are crazily complex and simply doing the semantically equivalent thing amounts to an emulation of one language in another, including all the implicit conversions, move constructors, copy constructors, overflow behavior, multiple inheritance, virtual dispatch, the whole mess. If you just do a full-fidelity source-to-source translation that amounts to emulation, you end up with an unreadable, gross mess.

Re: Deep learning to translate between programming languages

#29
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…

From my limited machine learning experience, it seems machine learning is great at pattern-matching/cargo-culting itself to 95% solutions.

Most of the time, porting between two similar languages can be done by cargo-cult pattern matching, but there are some very tough corner cases for semantic mismatches between the languages: thread safety (std::vector vs. java.util.Vector), iterator invalidation differences, hashmap iteration order differences, etc., etc.

Most of the time, you can ignore these minor differences between languages, but sometimes you need whole-program, or at least whole-module analysis to know if the semantic differences matter. Heck, you could probably mostly get away porting from a lexically scoped language to a dynamically scoped language without putting any effort into fixing up scoping issues.

I hope our tools eventually get good enough to perform these sort of transformations, but at this point, it's far from being safe to trust automated tools for this sort of thing.

Re: Deep learning to translate between programming languages

#30
post #26
post #10

Cool idea...I would be more interested in auto-documentation tool based on this.

That'd be truly remarkable as in actual magic. Take this rather simple example: PointList interpolate(PointList sample_points, OrderedRealNumberList points_to_interpolate); This function can be auto-documented from its name and the names and types of its arguments alone. No ML required - simple pattern matching and LUTs will do. But then again, do you really need a detailed documentation in such case? Where a documen…

Guessing !! N,X, and F are probably related to NE,XE, and FE "E" means "error"? Maybe. IERR is an error flag. Idiomatic fortran there.

Each of those variables will be defined later on, in the code. at least with a type (not required, but it is not 1960 anymore). In that declaration is where some comments would be.

          REAL*8 N ! Radius of the body in radians
Point being that fortran is not hopelessly opaque. A subroutine declaration is backed up with some more information.

(now if "implicit none" is not a requirement, then this all you get)

Love seeing some hard core numeric code. Precise and compact. No pointers, nothing sophisticated. Do loops, if statements, subroutine calls.

Post reply on HN