3 ms·
Noob question, isn't Python already based on C?
by curiousgal 10y ago
Noob question, isn't Python already based on C?
- timClicks 10y agoThe 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.
- azag0 10y agoThere are other implementation of the Python interpreter than the reference C implementation, notably in RPython (subset of Python), which is called PyPy, Java (Jython) or Cython (this compiles Python statically to C). One could say that Numba is also a very restricted Python interpreter.