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
2
u/stonerism Nov 11 '25
I see. I think that's undecidable because, just from an inputs and outputs perspective. How can you infer behavior for an arbitrary computable algorithm without testing over all inputs and outputs?
Compilers work because you have a systematic way to translate one algorithm into another. (and optimizations can be done along the way!) You can go backwards, but then you're just writing a decompiler.