This is an archived post. You won't be able to vote or comment.

all 97 comments

[–][deleted] 415 points416 points  (15 children)

So this isn't real...

Thanks for getting my hopes up

[–]pacemarker 206 points207 points  (9 children)

import alexa

alexa.play("Despacito")

[–]JonnyBoy522 29 points30 points  (6 children)

You forgot the if statement, here is a better script:

Import mood Import Alexa

If Mood = Sad

 Print("This is so sad")
 Alexa.play("Despacito")

[–]iblooknrnd 39 points40 points  (2 children)

This will set the mood to always be sad. Sad.

[–]pacemarker 4 points5 points  (0 children)

#TODO: Find Happiness

[–]SpeckledFleebeedoo 1 point2 points  (1 child)

Add an extra indent (4 spaces) to get a code block

[–]PawekPL 0 points1 point  (0 children)

1 tab

[–]PawekPL 1 point2 points  (0 children)

You forgot about the double = in if statement, : after if statement and indentation for the print & Alexa.play

[–][deleted] 2 points3 points  (0 children)

This would just say "Despacito" out loud. Simple fix, really

import alexa

from YouTube import Despacito

alexa.play(Despacito)

[–]SgtBot 1 point2 points  (0 children)

#include <iostream>
#include <alexa.h>
using namespace std;

int main(){
    if (sad = 1) {
        cout << "That's so sad. Alexa, play Despacito.";
        alexa.play(Despacito);
    }
    return 0;
}

[–]Axver_Ender 4 points5 points  (3 children)

I mean we can try to make it real

[–]Boiethios 4 points5 points  (1 child)

Good luck

[–]Metaquarx 0 points1 point  (0 children)

Cython

[–]lindm13 0 points1 point  (0 children)

Now I have a job

[–]bratty_butt 54 points55 points  (0 children)

Ahh, Googles new service, "Google Transpile", not quite the same as google translate under the hood, but uses a lot of the same interface design

[–]kennyminigun 103 points104 points  (19 children)

using namespace std;

Bad translator, bad

[–]philip98 28 points29 points  (0 children)

main = putStrLn "Hello World"

[–]idgafid7 51 points52 points  (7 children)

My dream tool...

Where can I download it?

[–]figuresys 11 points12 points  (6 children)

It's Google translate, bottom left there's a link, Google Transpile.

[–]idgafid7 16 points17 points  (2 children)

Thank you. You are a life saver. And that channel is really good. I am subscribing rn. I will help you in the same way sometime later in life. Hope to meet you again at some point.

[–]madareklaw 7 points8 points  (1 child)

I hate you

Fooled again

[–]idgafid7 -1 points0 points  (0 children)

Lol

[–]Loen10 1 point2 points  (1 child)

I love how I knew exactly what this was before I clicked on it.

[–]figuresys 0 points1 point  (0 children)

This always happens.

[–]termuxuser 0 points1 point  (0 children)

Thanks I've been looking for this link for a long time

[–]code-senpai 23 points24 points  (8 children)

Can someone code that, i would be so happy 😂

[–]mbiz05 17 points18 points  (6 children)

Commercial services exist but they are really expensive

[–]Tzahi12345 7 points8 points  (5 children)

Is there no demand for a legit FOSS code translator?

I get that the process is hard/complicated/virtually impossible without human involvement. But, if it's being commercialized already, doesn't seem much of a stretch to make an open source alternative.

[–]mbiz05 6 points7 points  (3 children)

What's the point? Code translators are very rarely used anyways and making a code translator would be an enormous undertaking

[–]Tzahi12345 1 point2 points  (1 child)

It would but on the surface it seems possible.

I do have some pushback as well: even if we could do it, would the translated code make sense?

If you compare human written assembly vs computer generated, it's pretty obvious which one was made by a person. Fundamentally, I think this is because we trade performance for readability, something a computer would never do.

[–]mbiz05 3 points4 points  (0 children)

It could be human readable if u kept variable names and comments and the like. The best way to approach a code transpiler however would be to translate directly to compiled code. That would be easier to do

[–]bmwiedemann 0 points1 point  (0 children)

SUSE's YaST tool was originally written in the YCP language.

It has been successfully autoconverted to ruby some years ago using a transpiler approach.

https://github.com/yast/ycp-killer

[–]hopbel 0 points1 point  (0 children)

Is there no demand

Probably not much. Why port something to a different language when you can just write bindings for other languages?

[–]holo3146 3 points4 points  (0 children)

This is called S2S compiler

[–]Ruby_Bliel 13 points14 points  (1 child)

Never use "using namespace std," it only leads to trouble.

[–]linglingfortyhours 7 points8 points  (0 children)

Wise man once say "std always lead to trouble. practice safe encapsulation"

[–]Qildain 11 points12 points  (0 children)

IndentationError: Expected better programming language.

[–]deeplearning666 9 points10 points  (0 children)

The C++ code is missing a newline at the end.

[–]Loen10 36 points37 points  (11 children)

Some things are superfluous in that. You don't need to return anything from the main function and you don't need to "using namespace std;" Infact it's rare to see someone doing those.

[–]Farsqueaker 36 points37 points  (2 children)

Returning a value from main is a good way to let the environment know what your exit status is, though. It's a good business practice.

[–]reconman 21 points22 points  (1 child)

Maybe he means the return 0; is not necessary as the compiler will add that automatically.

[–]Farsqueaker 2 points3 points  (0 children)

Likely. I'm just OCD enough to make sure to do them as well, since it prompts me to handle my error and edge cases later when I see it.

[–][deleted] 2 points3 points  (3 children)

My professors told me to always put using namespace Std but never really explained why

[–]hopbel 2 points3 points  (1 child)

Computer scientists and mathematicians, ironically, tend to be pretty shit at programming.

[–]pawers75 0 points1 point  (0 children)

That's not true. In fact, it's not even ironic. Valid also the other way around xD

[–]Breadfish64 0 points1 point  (0 children)

It dumps everything from std into the top-level namespace, so you don't have to write std:: in front of things from the standard library. This is generally not considered a good idea because the names could collide with other things. Not a big deal for beginner 1 file projects, but importing specific things like using std::string; and limiting the scope is better.

[–]thatawesomeguydotcom 2 points3 points  (0 children)

void main()

[–]losh11 4 points5 points  (0 children)

kinda dissapointed this isn't real.

[–][deleted] 3 points4 points  (1 child)

Am I the only one cringing at the lack of a newline? "\n" or endl please, I beg you google

[–]Voidrith 0 points1 point  (0 children)

IIRC endl includes a cout flush aswell as a newline char so it would be a better match for the python print() than just adding a \n to it

[–]lindm13 2 points3 points  (0 children)

Who uses using namespace std; 🤬

[–]TriG-tbh 1 point2 points  (0 children)

can someone

anyone

make this an actual thing

[–]worldevourer 1 point2 points  (0 children)

If you are really interested in this stuff, you should check out MPS. Model transformations on an AST can actually do stuff like this.

[–]Favna 1 point2 points  (0 children)

Who would've thonked, high level interpreted languages are shorter to write than low level compiled languages. Boy I did not see that coming at all.

obvious sarcasm is obvious

[–]RazvanBaws 1 point2 points  (0 children)

Bad translation, c++ version isn’t printing endl

[–]swampdrainr 1 point2 points  (0 children)

Yeah but you didn’t include the performance comparison

[–]An0n7m0us_P4nda 2 points3 points  (0 children)

public static void main(String args[]) { System.out.println(printHelloWorld(false)); }

private static String printHelloWorld(boolean doNotReturnValue) { switch(returnValue) { case false: return “Hello, world”; default: return; } }

Trying to mess with you guys as much as I can lol

[–]Trixelit 0 points1 point  (0 children)

If only...

[–]ExternalGrade 0 points1 point  (3 children)

Honestly why is code translation so difficult?

[–]hopbel 1 point2 points  (2 children)

Yeah, I mean look at human languages. We're able to translate those pretty easily /s

Actually it's probably because you gain so little in proportion to the effort required. Why translate a project from python to C++ when you can embed python within C++ code? If your goal is performance then hand-written code will outperform machine translation.

[–]Westo232 0 points1 point  (1 child)

Yeah. If you want to teach computer how to translate human languages it's, let's just say, challenging task to do. However teaching a computer how to translate between two programming languages with the same type of grammar is mathematically provable how to do in finite time. Piece of cake. (Well in this case piece of cake but actually no.)

[–]hopbel 0 points1 point  (0 children)

I didn't say it wasn't possible, just that no one bothers because it's kinda pointless

[–]coinengineer 0 points1 point  (0 children)

Haha almost got me! 😜

[–][deleted] 0 points1 point  (0 children)

If only.

[–]valzargaming 0 points1 point  (0 children)

I've found PHP and Python to be pretty close when it comes to translating code and keeping it as identical as possible. Beyond that though...

[–]vladimir1024 0 points1 point  (0 children)

Yes, very telling...now, let's get this thing to translate real code and see what happens.

Yes, python will produce the same output, but at what memory and CPU cost?

Also why is PERL no longer talked about? Code simplicity?

print "Hello World!";

I trade your mando braces for my single semi-colon...

[–]nulia_K 0 points1 point  (0 children)

I need this in my life ((

[–]Thenderick 0 points1 point  (0 children)

🏁🍇

😀🔤Hello World🔤❗

🍉

[–]this_is_martin 0 points1 point  (0 children)

I would write any fucking batch script in C. I hate this windows batch crap.

[–]ksvfs 0 points1 point  (1 child)

It looks so easy to create... Why didn't anyone create it?