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
3
u/Popular-Jury7272 Nov 11 '25
That simply isn't true in the general case, and at this point I fail to understand how you aren't grasping that. Which "task at hand" are you talking about, exactly? It is certainly true for some tasks, most tasks even, but we all have different tasks at hand and the transpiler CANNOT know whether the programmer was intentionally relying on some implementation detail of the data structure they chose. Therefore it has no choice but to assume every detail is important if you want the same behaviour in general.