Why Scala and Clojure

Many of the patterns in this book can be applied using other languages with functional features, but we will focus on Clojure and Scala for our examples. We focus on these two languages for quite a few reasons, but first and foremost because they’re both practical languages suitable for coding in production environments.

Both Scala and Clojure run on a Java virtual machine (JVM), so they interoperate well with existing Java libraries and have no issues being dropped into the JVM infrastructure. This makes them ideal to run alongside existing Java codebases. Finally, while both Scala and Clojure have functional features, they’re quite different from each other. Learning to use both of them exposes us to a very broad range of functional programming paradigms.

Scala is a hybrid object-oriented/functional language. It’s statically typed and combines a very sophisticated type system with local type inference, which allows us to often omit explicit type annotations in our code.

Clojure is a modern take on Lisp. It has Lisp’s powerful macro system and dynamic typing, but Clojure has added some new features not seen in older Lisps. Most important is its unique way of dealing with state change by using reference types, a software transactional memory system, and efficient immutable data structures.

While Clojure is not an object-oriented language, it does give us some good features that are common in object-oriented languages, just not in the way we may be familiar with. For instance, we can still get polymorphism through Clojure’s multimethods and protocols, and we can get hierarchies through Clojure’s ad hoc hierarchies.

As we introduce the patterns, we’ll explore both of these languages and their features, so this book serves as a good introduction to both Scala and Clojure. For further detail on either language, my favorite books are Programming Clojure [Hal09] and The Joy of Clojure [FH11] for Clojure, and Programming Scala: Tackle Multi-Core Complexity on the Java Virtual Machine [Sub09] and Scala In Depth [Sue12] for Scala.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.65.130