3 ms·
I don't think Python's approach is particularly more elegant than JavaScript, as they both distinguish property-as-value and property-as-function. It's just a m
by lifthrasiir 6y ago
I don't think Python's approach is particularly more elegant than JavaScript, as they both distinguish property-as-value and property-as-function. It's just a matter of where to put property-as-function (and unlike Python, JavaScript can have non-configurable properties which can be optimized). As property-as-function can subsume property-as-value, no built-in property-as-value would be truly elegant (Ruby is close, but not exact).
- sillysaurusx 6y agoI agree. Python's descriptor pattern was an endless source of confusion for me. But, it's much easier to do mixins in Python than in JS, even if the mro algorithm is a bit complicated...
- pansa2 6y agoSorry, could you clarify what you mean by “distinguish property-as-value and property-as-function“? How does Python distinguish between these two?
- lifthrasiir 6y agoThe very descriptor protocol exists to distinguish property-as-function (descriptor) from property-as-value (slot).