6 ms·
How Clojure deals with objects
- raspasov 12y agoOne important point is that once you instantiate like this (def a (ABC. "Roger")) the "name" property is immutable by default, which is different from most OOP languages where you'd have to mark the property as "final" or something like that. If you really need mutable properties you'd have to use deftype instead of defrecord and mark the property with a the proper hint as described here https://clojuredocs.org/clojure.core/deftype https://clojuredocs.org/clojure.core/deftype . In most cases, unless you're building a low level data structure, mutable properties are not needed; they are harder to reason about and much harder to get right in the face of concurrency and multiple threads.
- deleted 12y ago[deleted]
- nickik 12y agoFor those that want to go a bit deeper, prismatic has a information sheet. See: https://github.com/Prismatic/eng-practices/blob/master/clojure/20130926-data-representation.md https://github.com/Prismatic/eng-practices/blob/master/cloju...
- mateuszf 12y agoThis is very informative, thank you.