5 ms·
Could you elaborate on that?
by funklute 5y ago
Could you elaborate on that?
- hiptobecubic 5y agocpython's specific implementation is a "feature" that many things rely on, but even without that, python's semantics are very dynamic and it's hard to unbox anything in a way that is guaranteed not to be observable.
- orf 5y agoThere are a few different classes of introspection. The first is commonly used builtins like “isinstance”, “callable”, “getattr/hasattr” etc. The second is the inspect module that builds on that, allowing you to get the stack frames, inspect function signatures etc. The third is trackbacks, which need the stack and themselves are introspectable. The fourth is metaclasses (making dynamic classes at runtime). These are heavily used in Python, and are optimisation barriers. For example PyPy (Python with a JIT) disables optimisations when “inspect” is imported or used anywhere in the call stack.
- funklute 5y agoHow many of these "levels" (not to confuse them with actual classes) exist in javascript? Only the first one? (that said, I guess the fourth one (metaclasses) isn't a clear yes/no, since OO is very different in js)
- Jasper_ 5y agoHard to compare exactly with that classification, but JavaScript only has the first one, and arguably parts of the fourth one. metaclasses isn't really a major optimization hazard, it effectively boils down to hijacking the "class" syntax to instead run some custom code. It's used by things like dataclasses and the Django ORM to use class syntax to make a little DSL.
- ericvsmith 5y agodataclasses do not use metaclasses (I’m the dataclasses author).
- Jasper_ 5y agoApologies, I must have been confusing it with some other Python syntax tricks I've seen. I don't write too much Python anymore..
- pjmlp 5y agoSmalltalk JITs do just fine with introspection and certainty Python does not have some magic feature that Smalltalk lacks.
- orf 5y agoDespite being a totally different language based around message passing with no control structures? None of those are insurmountable, they merely make writing a JIT harder if you want to support them: it’s hard to inline a function call if the inclining can have a visible effect.