In case I want to translate a program’s code in a different programming language, I have these options: to use special software or to do it on my own (please tell me if there are other ways).
Personally I’m a beginner in C++, C# and Java. I’m not familiar with other languages. I’d like to try to do a translation of one of my C++ programs to C# and/or Java. But before doing that I’d like to learn about a technique or two about translating. I’d like to learn it from someone who is familiar with such thing.
So, can you tell me techniques for translating code from one programming language to another? And if there is something that I should know before I start translating, please tell me.
Learn both languages. Understand each language’s idioms and philosophy. Acquaint yourself with common coding styles and design patterns.
Read your source program, and understand what it is doing.
Think about how you would express the same overall goals in the target language, using the knowledge and experience gained from (1).
Rewrite the program in the target language.
(Counter-example: Your source is Java, and you see
String a = new String;. You open C++ and say,std::string * a = new std::string;. Wrong, go back to (1).)