4 ms·
> given all the lispers so fiercely dismissive of OOP I don't know where you are sampling your Lispers from. The only people I see blindly opposing OOP in Lisp
by koito17 4y ago
> given all the lispers so fiercely dismissive of OOP
I don't know where you are sampling your Lispers from. The only people I see blindly opposing OOP in Lisp communities are people who either (1) don't write a single line of code, or (2) know nothing about Common Lisp, the various Schemes with their own object systems, or even pause to consider what inspired Clojure's `defmulti` (spoiler: a Common Lisp library that used the Metaobject Protocol to allow for arbitrary dispatch in generic functions).
With that said, I do notice the Clojure community tends to be more against OOP than other Lispers, which I find golden because, again, the core language has things directly inspired from MOP libraries, and things like "atom watchers" are trivially an :AFTER method in CLOS, and so on.
- KingMob 4y agoI'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.