3 ms·
I'm guessing it's because the creator, Hickey, is anti-inheritance, and the Clojure community as a whole is uncritical of him. I actually agree that inheritance
by KingMob 4y ago
I'm guessing it's because the creator, Hickey, is anti-inheritance, and the Clojure community as a whole is uncritical of him. I actually agree that inheritance can be tricky, but is still needed sometimes, especially for interop.
Elsewhere in Clojure, he makes his preferences the defaults (like immutability over mutability), but always has an escape hatch when necessary. For inheritance, there's no escape hatch. Best you can get is a crippled proxy.
Another issue is how mutable fields in deftype work. Mutable fields can only be mutated from class methods (protocol fns in Clojure parlance), so you can't use outside helper fns. You can add helper fns to your protocol (like an interface), but that's a public signature, not generally meant to have internal-only fns.
The joy of interop with Java from Clojure is occasionally getting to discover that there's no good code reuse in certain situations with a family of classes, and realizing, oh yeah, this is why we wanted inheritance in the first place.
- jabradoodle 4y ago> For inheritance, there's no escape hatch. Best you can get is a crippled proxy You can use gen-class here. Granted complex Java interop trends toward a point where it becomes easier to write and expose a Java library; the option is there though.
- KingMob 4y agoHmm, good point. I always forget about gen-class, because I've been burned by AOT compilation too many times.
- pjmlp 4y agoIf he was anti-OOP he wouldn't have added most of CLOS infrastructure to Clojure.
- KingMob 4y agoIf he was pro-OOP, why not add all of CLOS?
- pjmlp 4y agoEasy, first of all, if he was anti-OOP, he wouldn't have added any of it. Secondly, what he added is enough for doing OOP in Clojure, in fact, very few OOP languages support everything that CLOS allows for, and that doesn't make them less OOP. OOP !== Java 1.0
- KingMob 4y agoAll kidding aside, it's obvious that Hickey is not entirely anti-OOP. But then, that's not what I said; I said he was "anti-inheritance". And my complaint is that unlike many other places in Clojure, there's no easy escape hatch for inheritance when you need it. `proxy` is limited, and `gen-class` involves AOT compilation, which can cause various problems.