On 17/10/22 10:13 pm, Denis Kotov wrote:
For example, PyObject is much better to implement using C++ class,
I used to think this. Python has OO features, C++ has OO features, should be a good match, right?
Well, no. Python's OO is very flexible and dynamic, C++'s is very rigid and static. CPython uses various low-level tricks that rely on structs being just "plain old data". The OO features of C++ wouldn't help nuch with that at all, and would often get in the way.
If you want a Python implementation that's less prone to memory management errors, I would suggest having a small kernel written in C, and write the rest using a tool similar to Cython that will take care of all the tricky reference counting for you.