How does CLOS relate to functions like Clojure and writing?

I recently worked with Clojure types and records, and I was wondering if they are very new concepts or are they inspired by the general Lisp Object System?

+6
source share
1 answer

I believe that they represent quite a few new innovations within Clojure.

CLOS is a fairly complex, fully featured, object-oriented system. It presents the various OOP methods that you often hear about and that exist in other object-oriented languages ​​- multiple inheritance, dynamic dispatch, general functions, etc.

Clojure takes a different approach: types and records are much simpler than a full OOP and are not designed to create a complete OOP system. Rather, I understand that the design is motivated:

  • The belief that many OOP methods are actually harmful when building large systems is implementation inheritance, for example
  • The ability to get maximum performance (the same as Java) for the most common case of polymorphism (i.e., separate sending by type)
  • Desire to solve a problem you can do in Clojure using deftype / defrecord along with protocols
  • The goal is to make all records / types immutable to fit the rest of the Clojure philosophy

If you want a traditional object-oriented system such as CLOS, you could build it in Clojure on top of types and records. You can also use Java style object orientation directly within Clojure. However, I believe that this is usually not recommended by Clojure experts - Clojure usually offers you different or better solutions to the same problems.

In general, Clojure tends to provide you with β€œsimple” tools that you can put together to solve the problem, rather than defining a complex structure at any point. This is an interesting philosophy discussed in this video with Stuart Hallow.

+12
source

Source: https://habr.com/ru/post/886123/


All Articles