deftype vs. defrecord

According to DEFTYPE VS DEFRECORD, you should distinguish programming constructs and domain constructs.

deftype is for programming constructs and defrecord is for domain constructs that need a custom type.

Hope this helps.


deftype creates a bare-bones object which implements a protocol.

defrecord creates an immutable persistent map which implements a protocol.

Which to use depends on what you want. Do you want a full ClojureScript data structure? Then use a record. Do you just want a bare-bones thing that does nothing but satisfy a protocol? Then use a type.

The two bits of documentation you reference use types because they're trying to illustrate protocols at the most basic level, and types have less "going on" than records, so to speak.

However, most real-world uses of object-like things in Clojure/ClojureScript need to store fields of data along with the object, and for that you should emphatically use a record, for the same reason you should use any of Clojure's immutable collections.