Is it common to convert code from one language to another?

For example if I see an application written in Go that I would like to use in my C++ system, would it be a good idea to rewrite the whole application in C++ (for optimizations and code coherency)?

Is that common practice?

When would it be a good idea?
When would it not be a good idea?
Does that application still get updates? Would you to be willing to convert (aka "port") every time it does? Do you have access to the code? Does its license allow porting? Do the original authors have a reason to use that particular language?

Can the application be interfaced with? Communicated with? Used as is?


Have you seen this (terrifying piece of code) anywhere:
1
2
3
  system("pause");
  return 0;
}

The "pause" is an application written in some language. The shown program runs that other application.

That is an example, where one definitely should get rid of the system("pause"); line and insert C++ code to achieve desired result.
Does that application still get updates?

Yes, but only core functionality is needed.

Do you have access to the code?

Yes, it's open source.

Does its license allow porting? Do the original authors have a reason to use that particular language?

No, the language was for personal taste.
Last edited on
Any code is just a program to do a task. Some types of code will run faster, some are easier to write, some maybe just easier to share.

Depending on the program requirements, you wouldn't normally recreate the wheel if it works for you. Many programs had to be re-written to support 64k or y2k and while the changes may not have been many, when you have to do that you want it in a language you can support long term.

So yes, there are many reasons to do it and sometimes it's just fun to have program you like in a code you can understand. It's also much easier to make changes to something you wrote compared to a program someone else wrote even if it's the same code because you have different styles.

its not an uncommon practice. I used to convert tons of matlab files into c++ which gave more than 10X factor speed increase, because we had a highly placed guy who only knew matlab.

I also had to get fortran code working with our c++. That we did by buying visual fortran and dumping to a dll that the c++ could use directly. A project to attempt to re-write it in c++ was taking way too long and turning into a mess, so we took the dll approach which was almost an instant solution.

many mixed language programs exist where the high performance sections are done in c++ or even assembler.

when is it a good idea... you don't want to waste time re-writing stuff, which can introduce bugs if the programmer is not expert in both languages, and it takes a long time for large projects. Its usually better to find a way to only re-write small parts, the ones that run slowest and get the most gains for the effort, and keep the rest in the original language and find a way to tie it together. Or do it when you need major overhauls to the code anyway, convert it while adding new functionality. There are too many case-by-case things to check.. what the original language is, the quality of the code, the amount of code, expertise of the coders doing the translation, what alternatives exist to the rewrite, and so many more things before you decide.

But it is done, when its needed, and it gives huge gains for some projects esp performance of moving from a poor language or a poorly written block of code to a better / faster implementation.
McAwesome answers.
Topic archived. No new replies allowed.