Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why convert code in one language to another?

I have heard of some compilers that convert code in one high level language to another
e.g Shedskin that converts python code to optimized C++.
I was wondering why would one ever try to do that. Why not directly write in the desired language itself?

The only reason I could think of was may be compiled languages like C/C++ are better than interpreted ones performance-wise.

Any more insights are welcome.

like image 880
sud03r Avatar asked Jul 27 '09 17:07

sud03r


Video Answer


2 Answers

Well if you think about it, any compiler converts to another language: machine code.

If you go with that argument, anything other than assembly is pointless. (Actually assembly would be too. Real men type hex opcodes by hand.)

You would use one language to convert to another if you want to write from a higher level perspective or if you are more comfortable in one language than another.

For example, would you rather write and debug a few hundred lines of network code in one language or use 5-10 lines in another language?

like image 128
samoz Avatar answered Sep 30 '22 05:09

samoz


It is often handy to convert one part of a codebase into a different language if you want to reuse that code in another project.

For example, say you had a python application which used some handy utility functions. Later, you're writing a C++ application, and need that same functionality.

You have two options - either use some form of bridge to call the python code from C++ (which can be clunky at times, although it is possible), or rewrite the routine in C++. Translation tools can simplify the second option.

like image 44
Reed Copsey Avatar answered Sep 30 '22 03:09

Reed Copsey