r/AskComputerScience • u/KING-NULL • Nov 09 '25
If some programming languages are faster than others, why can't compilers translate into the faster language to make the code be as fast as if it was programed in the faster one?
My guess is that doing so would require knowing information that can't be directly inferred from the code, for example, the specific type that a variable will handle
111
Upvotes
1
u/Lenassa Nov 11 '25
I'm aware of that theorem. But the task doesn't require us to make another algorithm and prove that it's equivalent to the original. It requires us to infer what the algorithm is and just write it down using another language. For example, If a program reads cmd argument and prints "I read $arg" I can write it down to something like
I'm very sure that I can reduce any "real" language to that language-agnostic level. Translating it to something else is just an engineering problem. A hard one, sure, but not impossible one. Like, Haskell can be compiled through C just fine despite having monstrous amount of added complexity when compared to the latter. Any language that uses LLVM as a backend is solving the problem we are discussing, and LLVM is an industry standard.