Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
AI converts between hundreds of programming languages (codelanguageconverter.com)
107 points by yodon on Sept 29, 2022 | hide | past | favorite | 58 comments


Tried pasting a big piece of code. "Whoah, that's big, try something smaller." Ok, paste small snippet of code. Click "translate". "Sign up first". Urgh, fine, this looks just about exiting enough to try, but barely so.

After signing up, I have zero credits, without a single translation performed. I mean, not that I expect free lunch, but I'm also not gonna pay money before seeing a single 10 line example.


At least the samples seem legit, in the sense that some break the algorithm badly enough that we can be confident they weren't hard-coded lol.


ha ha


Plus a trivial translation is just that, trivial.

It’s not going to rewrite the huge web of dependencies that any given app consists of, nor will it recreate the various differences between runtime environments for interpreted languages.

It’s essentially a cute party trick.

Stuff like copilot is where I see the utility in the space.


Not today anyway, but it's not like this type of conversion lives in a unknown future.


There are some bits that just simply cannot be translated. For example, you can’t just “translate” a stdlib function from a high level language into a low level language, there’s likely no comparison in the low level language.


I was about to come back to this thread and post almost the exact same comment. I didn't even get 10 lines - I just converted the 3 line typescript example that was already there, and couldn't try anything else. There's no way I'd ever pay for this.


I used GitHub Copilot to translate a few small programs, from Javascript to Python.

Results:

- single lines went over well, and even became idiomatic in the destination language

- snippets translated well

- for two snippets translated separately, the 2nd snippet didn't understand the original context and got confused. Lesson: translate a whole file at once, or you'll have to fix cross-function references/names.

One test I thought didn't work. My 100 lines of (admittedly crappy) Javascript got cut off. Actually... it worked! It translated 100 lines of JS into 50 lines of idiomatic Python! I was extremely surprised.

More results

- original had a driver function and a worker function. The translated code just inlined everything. I'd have preferred the multiple functions be preserved, but it's okay.

- idiomatic Javascript was translated to idiomatic Python

- it used modules I'd never heard of. I thought the AI had just made things up, but the modules were actually real! Very happy with this.

- it also used old modules. I had to rewrite several lines and retarget the code to use a modern module, vs the original which was deprecated.

Bottom line: at least the AI I tried (Copilot), is effing magic! We saved our client probably $1000 in just one usage of this tool.

I'm going to continue paying for this out of my own pocket, to use for learning new languages, modules, and for translating the occasional small program.

Huge caveat: talk to your Dir Eng or CTO about sending their proprietary code to some random service on the internet. They probably will NOT like it. Thus, AI can only be used in occasional "I'm starting from scratch and learning this" type situations. You can NOT use AI on business code without company consent, which dramatically limits its usefulness for the moment.


How did you instruct Copilot to do the conversion? I've always used it just as a smart auto-complete.


Seems completely broken now; like others, I tried to test something, found I had to sign up, signed up, and found I have "0 free credits".

I really wanted to see what it was gonna do for Python -> C++ converting some nested dictionary and list comprehensions:

    def foobar(x, y):
      return {
        _: __
        for _, __ in zip(
          [_ for _ in x if _ in y],
          [_ for _ in x if _ not in y]
        )
      }
        
    {3: 1, 4: 2} == foobar([1, 2, 3, 4], [3, 4, 5, 6])


I bought some credits. Here is the result (Python to C++):

  std::map<int, int> foobar(std::vector<int> x, std::vector<int> y) {
    std::map<int, int> map;

    for (int i = 0; i < x.size(); i++) {
      if (std::find(y.begin(), y.end(), x[i]) != y.end()) {
        map[x[i]] = x[i + 1];
      }
    }
    
    return map;
  }


Thanks for checking into that... doesn't look like the AI is even close to ready for prime time right now as this is not the correct translation:

    #include <algorithm>
    #include <iostream>
    #include <map>
    #include <vector>

    std::map<int, int> foobar(std::vector<int> x, std::vector<int> y) {
      std::map<int, int> map;

      for (int i = 0; i < x.size(); i++) {
        if (std::find(y.begin(), y.end(), x[i]) != y.end()) {
          map[x[i]] = x[i + 1];
        }
      }

      return map;
    }

    int main(int argc, char** argv) {
      std::vector<int> ex{ 1, 2, 3, 4 };
      std::vector<int> wy{ 3, 4, 5, 6 };
      std::map<int, int> result = foobar(ex, wy);

      std::cout << "{";
      for ( const auto &item : result) {
        std::cout << item.first << ": " << item.second << ", ";
      }
      std::cout << "}" << std::endl;
    }
It outputs:

    {3: 4, 4: 0, }
But it SHOULD be getting:

    {3: 1, 4: 2, }


First underwhelming AI post on the frontpage. Thank god our jobs are safe atleast!


Writing code is rarely the problem anyway. Understanding the problem and devising a suitable solution given the full context is where the magic is. And since most humans have a hard time even accurately describing a problem and full context, there's no threat that AI will replace developers.

If we can build up an immense library of clearly defined problems and solutions, with variants which fit with all conceivable unique contexts, then maybe it will become possible for AI to provide useful assistance.

It would be a good goal to do what I describe, as it would result in many fewer bugs in software. The risks then would be either misidentifying the problem (and therefore getting a solution which doesn't fit the need) or providing inaccurate context which allows for suboptimal selection of a predefined solution.


> If we can build up an immense library of clearly defined problems and solutions, with variants which fit with all conceivable unique contexts, then maybe it will become possible for AI to provide useful assistance.

Agreed. What you're describing (an immense library of problems and solutions) is essentially what's in the head of a very experienced developer. A system that helped surface those in a simple way for "new" problems so that people aren't constantly reinventing the wheel and making the same mistakes would be great. I've seen ideas about similar "tacit knowledge" systems in other domains (though I'm not sure there is a good one yet). For software, such a system would be way more helpful, and a much better goal, than this kind of idiot-savant gpt stuff


Programming is 10-20% of the job, sure it's fundamental but even if an AI could generate optimal code solutions for most use cases it'd still never replace us...

...probably.


The interesting bit will be when the AI is smart enough to take an “easy” language like Typescript and convert it to rust or c++


It still won't help with setting up the development environment to be able to compile rust of the week or c++??. Both of which have dev communities which adopt forwards incompatible features fairly rapidly so the environment in your distro probably won't work as is. But eventually, maybe they AI will set that up too, https://www.commitstrip.com/en/2019/03/15/css-css-everywhere...


So what we need is an AI that completely understands the problem space and can tell us what to code.


I think I broke it.

    Input: TypeScript
    Output: QuakeC
    Code: Sample 3
Seems to spin forever. (Which makes sense, as QuakeC is incapable of the constructs in Sample 3).

Edit: after a few minutes spinning it's... Spewing a lot of nonsense. It seems to be dumping every variable combination it can "think" of that it has seen in QuakeC.


TypeScript to Fortran is also broken, generating lots of dlopen/dlsym/dlclose calls (one for every variable, it seems), but never actually doing anything else with it.

For what it's worth, Sample 2 generates syntactically invalid code, having `:` instead of `::`. Sample 1 is actually working code (but relies on the implicit typing rules, which gives you the default real kind instead of double precision reals). Interestingly, translating Sample 1 from Rust to Fortran suddenly generates a subroutine instead of a function, but does generate types.


Prolog also seems to be broken; it keeps importing modules over and over


I think maybe they're being a bit too ambitious by trying to cover so many languages. Obscure languages won't have nearly as many examples to train on.


Tried CHIP-8 and so far I got

// TODO: Translate the above Rust into CHIP-8

### TODO

and now it got stuck on emitting some assembly. I don't exactly know what because CHIP-8 doesn't have an assembly representation.

It printed this 16 times

  @0000
    LD V0, [I]
    LD V1, [I + 1]
    LD V2, [I + 2]
    ADD I, 3
    LD V3, [I]
    LD V4, [I + 1]
    LD V5, [I + 2]
    ADD I, 3
    LD V6, [I]
    LD V7, [I + 1]
    LD V8, [I + 2]
    ADD I, 3
    LD V9, [I]
    LD VA, [I + 1]
    LD VB, [I + 2]
    ADD I, 3
    LD VC, [I]
    LD VD, [I + 1]
    LD VE, [I + 2]
    ADD I, 3
    LD VF, [I]
    LD I, V0
    LD V0, [I]


I had a particularly funny result: Trying sample #3 (put a record into S3) from Typescript to Python, it reliably... outputs a completely different program, which instead downloads an image from S3 and resizes it in /tmp. Weird.


Ditto for converting sample #3 from Python to Rust...it doesn't even try to interact with S3 at all, it just saves the image to a path specified in args (twice, overwriting the first image). Also, the comments it writes are incorrect.


Just tried the default example from C to Forth. It gave an answer but also appended two other commented Forth functions to it.

Also, this almost immediately adds a signup wall not for the real product, but to the little demo box on the home page that makes it not worth playing with


Ah damn I ran out of free credits after like 2 basic runs.

Definitely not enough of a taste to convince me to spend money on this. Might want to adjust that freemium model.

It's a cool idea for sure and could definitely be useful though.


Asking me to sign up just to give it a little try made be hit the close tab button real fast.


Interesting going from untyped languages to typed languages, as an inference needs to be made.

For example, in JavaScript:

function add(a, b) {

  return a + b;
}

converting to Go, it becomes:

func add(a int, b int) int {

  return a + b
}

Where as the original JS version works with integers, floats, strings, arrays, etc.


Same for ruby and elixir. Assumed type..


I applaud the effort of whoever put this together, but it is a toy, and a broken one at that. Trivial examples break it easily. When an "AI" like this can take 5,000 lines of SAS in a single file where execution starts at the top and finishes at the bottom with nary a function or external module to be found written by a government employee who hates his job and really doesn't think you should be reading his source code and can turn it in to comprehensible Python that is readable I might be interested. But this is most likely going to be a case of GIGO.


I have written translators and they are really hard. I think training on code bases is the way to go but I am skeptical overall that it is even worth the effort. The problem is that the translation doesn't get you all the way there. The code produced is buggy and wrong in most cases. You probably get a better result from re-designing and re-implementing.

I wonder what the data being trained on even is. It has to include successful translations, right? There are not many of those. Not enough for a good result.


I’ve written translators that also had to consider pattern changes. The amount of training to translate code effectively is enormous to be effective at scale. I assume this is segmenting separate models based on each language permutation.

I would love to see AI applied to predict algorithms and provide intelligent recommendations.


I think it depends on how urgent the migration is, and how much you're paying to fix the bugs.

If the systems works functionally but the infrastructure (?) hasn't aged well, and there's only time / budget to switch horses, that might be the sweet spot.


I wish the price structure was a lot more explicit.

I can buy 20.000 credits for $5. This will give me "around 5-20 code conversions"

That is a pretty big difference. What are the metrics to estimate what a conversion will cost?

I am not critiquing that you cant have a fixed price since length, complexity, edge cases varies significantly but I would like some indication.


Yet another simple gpt3/codex wrapper. Monetizing is hard if not much value is offered on top of the AI.


I think the best case something like this could achieve is a syntax translate and nothing more.

At best I'd get Ruby code with elixir syntax.

Programming languages require thinking about memory and code differently. That's why we have them.

I'd be interested to see this in elixir :)

while (s++ = t++);


When trying Sample Code 3 converting the TypeScript to Python the conversion was incorrect. Probably worth swapping that out for another sample if the owner is in this thread. As I was writing this I noticed that this wasn't a Show HN post.


I just want AI that will write a unit test for me.


I’m remembering a joke from my childhood.

Guy is in a computer store. Salesman says “This will halve your workload”. Guy says “Great, I’ll buy two!”

We’re nearly there now.


What a good idea! It could also relatively easily verify if it's correct and only return a result when the test is passing and all the lines (or even paths) are covered.


Have you tried Copilot? It writes my unit tests 80% of the way. It’s the main reason I pay for it (I hate writing tests).


Not a good sign that this website thinks Java is an acronym. And has both "Lisp" and "Common Lisp".


Demanding a signup for a toy like this is rude.

Like demanding an email address to tell someone the punchline to your joke.


Checkout https://text-generator.io which can also be made to translate between human and computer languages with prompt engineering, has a nice 100 requests a month free teir


You can accomplish something close to this with GitHub Copilot (or OpenAI Codex), just write some code in a comment and then say “rewrite the above (language) code in (language)”. Typing the first few characters of the converted version yourself helps with accuracy.


I tried it with Erlang. Their "Sample Code 2" does not generate working code (lowercase variable assignments), and their "Sample Code 3" does not even generate valid syntax, flat out leaving bits of typescript untranslated.


Hmm, it wasn't able to convert from Fortran to Matlab for the first exmample, but it seems to have produced legitimate C++ from Fortran.

So I guess... this spells doom for the quants but the scientists can sleep soundly.


Sample 2, typescript to c++: infinite loop. It just keeps spitting out code


What's weird is that it starts generating a function to print out its parameters in ts then immediately translates it to cpp, both initiated with comment lines which seems similar to copilot.


Do you plan to support additional languages? I'm working on porting a library from web (ts) to roku (brightscript)


Tried converting a Typescript function that returns the sum of a and b, and it generated: +

Clearly not ready for prime time.


Don't try to convert sample code two from TypeScript to C++. Or rather do... it goes into a loop.


Sample 2, TypeScript -> Common Lisp... might be a recursion joke? :)


RUBY... def add(a, b)

return a if b.zero?

return b if a.zero?

a + b

end

Now lets see elixir :)

I say the trial should allow at least one bit of code that we provide.


finally: fully automated memory corruption


ha




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: