Monday, September 21, 2009

Benefits of using Clojure (Lisp) in web/enterprise development

This post is my attempt at replying Ivan's question:

Benefits in web/enterprise application development are more of a corollary to how Clojure/Lisp addresses the problems in imperative-style development. To help myself substantiate that statement, I would rather point you to these:

Rich Hickey's talk at the JVM Summit

Paul Graham's story about ViaWeb

The practical web/enterprise app development scenario today includes
1. very high concurrency (traffic)
2. multi-core processors (hardware)
3. lock-based multi threading (prog model)
4. syntax and semantics bloat (Java)
5. complex business logic (business)
6. time-to-market issues (business)
7. performance issues (hardware / prog model)
8. scaling issues (hardware / prog model)
9. external Java libraries (prog model, Java)
10. lot of coding and bug-fixing (prog model)

Clojure is LISP-1, and has
(a) absolutely minimal syntax and great Java compatibility, which helps you deal with 4, 5, 6, 9 and 10
(b) very fast persistent data structures (with immutability and structure sharing), which help you deal with 3, 4, 5 and 10
(c) multiple flavors of anonymous functions (lambda) that make your programming model simpler
(d) macros, that let you extend the syntax and generate DSLs
(e) meta-programming, that lets you create very powerful programming constructs
(f) multi-methods, that are way more powerful than polymorphism
(g) type hints, that help you deal with 7
(h) multiple elegant concurrency solutions (few relevant links listed below), which help you deal with 1, 2, 3 and as a result also 8 to some extent

(i) data structures that are functions and functions that are data, which helps you mix and match constructs in your programming model with extreme flexibility
(j) last but not the least lots of parentheses :-), which are actually a lot friendlier than they may seem at first (to the extent that they are actually a feature to help reduce syntax clutter)

As you would notice, Clojure provides a much higher power-to-weight ratio (in terms of expressiveness, flexibility, fitness and hygiene) when compared to other imperative languages. However, there are scenarios where you may be better off using Java rather than Clojure -- those include cases where pure performance matters more than everything else.

This post barely scratches the surface of what Clojure is all about. Take some time to explore the language -- I hope the benefits you discover will be be nothing short of amazing.

No comments:

Post a Comment