AI converts between hundreds of programming languages
codelanguageconverter.com
codelanguageconverter.com
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.
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.
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.
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]) 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;
} #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, }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.
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
...probably.
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.
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.
// 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]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
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.
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.
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.
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 would love to see AI applied to predict algorithms and provide intelligent recommendations.
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.
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++);
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.
Like demanding an email address to tell someone the punchline to your joke.
So I guess... this spells doom for the quants but the scientists can sleep soundly.
Clearly not ready for prime time.
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.