Clojure is a better Java than Java


#1

Originally published at: https://purelyfunctional.tv/article/clojure-is-a-better-java-than-java/
How is it possible that Clojure is better than Java at its own game? Hear me out, then decide for yourself.


#2

A nice combination of chaining and better null handling for Java interop from Clojure is using the some-> macro. If you just use thread first “->” in a chain of java method calls you can get a NullPointerException anywhere along the chain, some-> guards you against that.


#3

I remember before Java first emerged about 1996 or so… we already had some really amazing dynamic languages and IDEs. Common Lisp is a bit overwhelming at first, but once you learn it it really is amazing and a pleasure to use, With a little work you could make Lisp programs run really fast! Smalltalk was a clean and amazingly powerful language built throughly on object-oriented concepts. Apple Dylan was a pretty amazing language design. Python emerged in 1991. Several great IDEs for Common Lisp existed, including Macintosh Common Lisp and Harlequin Liquid Common Lisp (now Lispworks), not to mention Lisp Machines (which I never got to try…)

Computers were much much slower. For that and other historic reasons, the majority of programmers used C and C++ or older languages.

Compared to other options, the design of Java was reactionary from the start. As an object-oriented language, it omitted many interesting features of other object-oriented languages. My impression is that Java was an attempt to drag the C++ community into using object references (instead of pointers) and garbage collection. In order to do this they borrowed most of the C/C++ syntax and made Java comfortable for C and C++ developers. The design dumped many more advanced language features. A rigid type system, no traits or mixins, no closures, no type inference, no multiple dispatch, no interactive development or live coding. It did do some good things, but overall a real step back.

Fast forward to now. Clojure is great of course, but beyond that, even JavaScript has adopted many of the features of 1990s lisps. GC is no longer controversial and passing closures around is accepted practice. Older languages like Java and C++ have now been extended to include closures and (Java) has the equivalent of traits. New languages like Julia implement multiple dispatch (one of the really great features of Common Lisp and Dylan). Statically typed functional languages have become more common and more powerful. Scala, F#, and OCaml mix functional and object-oriented paradigms. Python got quite a bit more powerful, gained APL-like array operators (via numpy), and has been adopted as a standard in the data science community. Wow! Things are much better now.

  • We spent the years 1995 - 2010 or so sliding back then slowly catching up to the best languages and IDEs and ideas available before. Focusing on “enterprise computing”. Fifteen years in the wilderness. What an enormous waste. Java fits in to this story.

  • I have not figured out why there was a huge step backward in technology and technical culture at that time. The same period corresponded with AI Winter and cultural retrenchment in many other areas of life.

  • Computers are much faster now and have much more storage. The technology of compiling dynamic languages has improved so they need not be that much slower than statically typed languages.

  • Open source software has given developers access to much richer and more diverse resources than ever before. It used to cost thousands of dollars per year for a license for a compiler or IDE.

  • The internet has made it possible for technical and intellectual communities to survive with smaller numbers, geographically spread out, and/or with little or diffuse financial resources. This has led to a flowering of new programming languages and paradigms, a revival of AI research, but also a revival, for example, of interest in real and simulated analog electronic musical instruments, a technology which I surely thought was dead in the 1990s.

So we are living in a very exciting time. (IMO and a very scary time politically, but that is another story…)