Clojure vs Java: The benefit of Few Data Structures, Many Functions over Many Unique Classes


#1

In Clojure we use again and again the same data structures and have many functions operating on them. Java programmers, on the other hand, create a unique class for every grouping of data, with its own “API” (getters, setters, return types, …) for accessing and manipulating the data. Having been forced to translate between two such “class APIs” I want to share my experience and thus demonstrate in practical terms the truth in the maxim

It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures.

Notice that I speak about data and data-carrying classes, not about “business logic,” which would be implemented by methods on the said objects in Java and by (preferably pure) functions in a namespace in Clojure.

Read more