3 ms·
The reference Python interpreter is implemented in C, but that doesn't mean that Python equals C. Implementing programming language interpreters is a bigger to
by timClicks 10y ago
The reference Python interpreter is implemented in C, but that doesn't mean that Python equals C.
Implementing programming language interpreters is a bigger topic than a HN topic... but in general when things are easier from the programmer's perspective, then the machine needs to do significantly more work to get things right.
This is especially true in Python, where 1 + 1 doesn't necessarily mean "add one to one" because the integer literals (1) and the addition operator (+) can be overloaded to mean different things. Even at runtime, it's possible to have the same written code and different semantics.
C's semantics are much closer to how the hardware operates. In order to code effectively and efficiently in C, you need to understand much more nitty gritty details about how computers operate.
- azag0 10y agoI know what you wanted to say, but you didn't give the best example. "1 + 1 == 2" will be always true in any Python code since all those symbols are either operators or literals. I believe you cannot change dynamically how the interpreter interprets operators (that is, "+" always calls __add__ and __radd__) or literals.