4 ms·
The magic of Clojure is that if a problem can be solved with an interface Clojure lets you solve it with an interface. It doesn't have any magic to show off, it
by roenxi 1y ago
The magic of Clojure is that if a problem can be solved with an interface Clojure lets you solve it with an interface. It doesn't have any magic to show off, it is just a relentless implementation of a lot of basic good ideas.
- geokon 1y ago??? I don't understand. Did you not read my comment? I just explained how your seemlessly extend records across library boundaries. It's not just solving with interfaces
- roenxi 1y agoI don't agree with your characterisation of what the magic of protocols is. A protocol is the lightest possible thing that captures how two things can interface. That is magic in a way, but it is also the end of it, Clojure does a masterful job of keeping concepts tidy. In terms of what you can do with protocols, you can indeed do that in many languages. Clojure is pretty smooth but there is nothing stopping anyone implementing any interface on any object in most languages; build some sort of adapting whatever. It is rare enough in practice that the extra dev work isn't a major problem. And as a bonus observation, any time your example of how to use a programming feature involves animals it is a fake use case. It is a bad sign because it suggests that the benefit doesn't have a real world use.
- wtetzner 1y ago> Clojure is pretty smooth but there is nothing stopping anyone implementing any interface on any object in most languages I mean, this is false for Java. Creating a wrapper can end up being a big mess if you need to expose the functionality of the inner type. And if you need to preserve the actual underlying type, you end up needing wrap/unwrap all over the place. I think you're underestimating the cost of needing wrappers. I would also argue that "it's rare enough in practice" because people just avoid doing it, either just avoiding using a library because it would be too much work to wrap, or more likely, just writing directly to the implementation instead of using an interface.
- geokon 1y agoMmm, I don't think what you're saying is true? I'll be honest I haven't touched Java in a long time, and I'm haven't had to extend my Clojure code this much before (but it's nice to know that I can - and use protocols with confidence) Say LibraryA has some record.. LibraryB and LibraryC `extend-type` the record and implement additional functionality by implementing protocols.. Now you want to us both libraries in your application and use this record with both extensions. In Java this is forbidden due to diamond dependencies restrictions. You can use multiple protocols in Java, but you can't have the protocols implemented (there are default methods but they don't have access to the Record's state) Is there some way around this..? As far as I understand there isn't. Furthermore, all the extensions need wrappers and need names. Nobody is doing this b/c you'd go nuts. But in Clojure it'd be a natural way to extend a library. For instance (defprotocol MyProtocol (foo [x])) (extend-type clojure.lang.PersistentVector MyProtocol (foo [x] (str "Vector of size " (count x)))) (extend-type clojure.lang.PersistentList MyProtocol (foo [x] (str "List of size " (count x)))) I can keep using vectors and lists as before and have new functionality. I don't need a new wrapper to think about
- roenxi 1y agoI can't claim to know much of anything about Java. But this sounds like it might be linked to Java's type system and Clojure is an untyped language. From what I know of typed languages I don't see how a Clojure style interface could be implemented in a typed language or why someone would want to do that if they have chosen a typed language. So I don't understand the point and I don't know Java. I'm fairly confident that Java is technically capable of doing anything Clojure can since in the extreme case someone could implement a Clojure library callable from Java. In a similar way to how the Python community claims to do machine learning despite all critical code actually being in C++.
- geokon 1y agoOkay... I thought you had something actually to contribute to the conversation You start off incredibly dismissive > Clojure is pretty smooth but there is nothing stopping anyone implementing any interface on any object in most languages; build some sort of adapting whatever Then i explain how it seems not possible.. I mean maybe I'm wrong and missed some angle. I'm really willing to learn and change my mind here. And yes, the dynamism is part of the whole point. And then you just handwave it away, making some vague analogy to Python and ML.. and don't actually have any technical input at all. What a frustrating waste of my time