4 ms·
Classes are a good feature to have, provided you aren't forced to use them and you don't go overboard with OOP (cough Java). Any equivalent becomes rough in som
by hot_gril 4y ago
Classes are a good feature to have, provided you aren't forced to use them and you don't go overboard with OOP (cough Java). Any equivalent becomes rough in some common use cases. I might be wrong, but it seems like Python approached it from that direction, with Py2 having half-baked classes.
Classes are also nicer to deal with in dynamically-typed languages, or at least ones with very smart automatic static typing. You don't get stuck dealing with all that pedantry.
Btw, your example works fine in OOP. It'd be parallelogram -> rhombus -> square. But yes there are examples of it not working well.
- ogogmad 4y agoAh, I meant rectangle instead of parallelogram. Rectangle, rhombus, square. What's the inheritance hierarchy?
- hot_gril 4y agoYeah, that's an example of inheritance not working. Python does support multi-inheritance, but it's messy. Best you can do is interfaces instead of subclasses. Honestly can't remember the last time I've subclassed something and actually cared to inherit methods/variables.
- rileyphone 4y agoThat's because there are two separate types of inheritance that often get conflated in popular OOP languages: subclassing (implementation inheritance) and subtyping (specification inheritance). The 'types' here are the interfaces in typical OOP languages, though their (especially Java) failure to orient types around them create much of the pain developers experience. See https://www.cs.utexas.edu/~wcook/papers/InheritanceSubtyping90/CookPOPL90.pdf https://www.cs.utexas.edu/~wcook/papers/InheritanceSubtyping...
- imtringued 4y agoNo language on earth does data dependent typing.
- hot_gril 4y agoRight, but some can infer your types with much less manual input than in Java or C++. Rust does more automatically. Or actually C++ is the most automatic if you really abuse templates, but the compiler error messages become impossible to read.