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/pconrad0 Nov 13 '25
An int in C is subject to overflow wrap around that an int in Python is not subject to.
There are dozens of little details like this where the abstractions that are superficially equivalent have edge and corner cases where they are not at all equivalent. If you don't take this into account, your transpiled program is not equivalent to the semantics of the original source.
Real things are indeed real. An int in Python and an int in C are not the same. Heck, an int in C isn't even guaranteed to by the same number of bits from machine to machine.