Now you might wonder what are the two best programming languages I am talking about? You should know by now that the first one is Smalltalk. The second one is Clojure. Clojure cures the disease of writing hundreds of classes to deal with hundreds of different composite data structures. Why? Because you can't. The power of Clojure's sequence abstraction and provided core functions that operates on them gives you superman powers to manipulate data. For example, following simple function will condense strings by removing extra white spaces:
(ns compact "compact a string by removing extra white spaces") (defn compact [s] (reduce #(str %1 " " %2) (filter #(seq %) (seq (.split s " ")))))
(compact " Your uncompact String ")-> "Your uncompact String"
I am not even contemplating the Java implementation of this simple function. This is all good. Why do I mention Smalltalk as the first one, you wonder. Here is why:
You do not need to implement the compact function. You just tell the String Object to compact itself. Here you go:
' Your uncompact String ' withBlanksCondensed-> 'Your uncompact String'
You just send the "withBlanksCondensed" message and you are done. Clojure gives you the option of being practically lazy, but Smalltalk makes you one. So learn yourself a little Smalltalk and Clojure if you are really serious about programming with elegance and laziness.