Flowchart for choosing the right Clojure type definition form
Clojure offers a number of different forms that define types (and generating Java classes. Choosing between deftype, defrecord, reify, proxy, and gen-class can be a tripping point for those new to Clojure.
I’d obviously like to make such decisions easier for everyone. I know that many people learn best through visual aids, so I’ve been working on a flowchart that attempts to encapsulate some of the significant choices that go into deciding between the different type-definition forms. A draft of it is below; let me know if it is helpful to you (or not!), how you think it could be made better, etc. I’ll update the flowchart in-place as necessary.
“The ‘Interop Zone’” demarcates use cases (e.g. needing to define multiple constructors) and forms (proxy and gen-class) that are exclusively the domain of Clojure’s JVM interoperability support. Using these forms is fine, but be aware that by doing so, you are stepping outside of Clojure’s “native” abstractions; unless you are defining a type for the express purpose of meeting interoperability requirements, one of Clojure’s simpler type-definition forms may suit your needs better.