Over a million developers have joined DZone.

The Growing Clojure Ecosystem - A Data Structures Library and Mocking Facility

DZone's Guide to

The Growing Clojure Ecosystem - A Data Structures Library and Mocking Facility

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

As the JVM-languages continue to grow in popularity and deployments, some have speculated about the next ' heir to Java'.  Many believe that the programming world has evolved to a stage where platform is more important than language.  Nonetheless, there are a few languages, like Groovy and Scala, that are more popular than the other JVM-languages.  I would also bet that Clojure is going to join the Groovy/Scala echelon of popularity in the next few years.  Alex Miller and (Uncle) Bob Martin are two prominent developers who have found Clojure to be very useful.  The number of tools and frameworks for Clojure have grown rapidly as well.  I found two interesting Clojure projects that were posted on GitHub in just the last few months.  Here you'll find a description of each of them.


Karl Krukow loves Clojure, and he especially likes using the data structures.  Even though Clojure is distributed as a .jar, the structures work best within Clojure.  Since many clients require that he use Java, Krukow has authored a library that is able to capture some of the benefits of using Clojure data structures within Clojure.

clj-ds is not dependent on the Clojure runtime and does not run any Clojure bootstrap process, so calling certain methods on PersistentHashMap that require loading of the entire Clojure runtime will not cause delays for a Java user.  clj-ds will also support generics (Clojure doesn't have them) for the Java data structure library.

Clojure data structures are currently implemented in Java, but the language is moving towards being completely implemented in Clojure itself.  This could make the data structures even more inconvenient to use in a Java environment.  So the clj-ds project will maintain Java versions of the code.  

Other JVM languages such as JRuby, Groovy, Jython, Scala, or Erjang could benefit from Krukow's implementation. 



atticus.mock is an alternative approach to mocking where the mocked function can be implemented as an inline function to perform any checking or return value calculation.  The project currently has two macros to wrap the body of a mocked function.  One will verify that a function is called once, and the other will verify that a function is called a predetermined number of times.

The Once macro
;; define test, that should be called just once
(deftest mock-test
[(f [arg]
(is (= arg 1) "Check argument")
(is (= 1 (f 1)) "Call mocked function"))

Atticus includes this all Clojure mocking facility.  The project's author, Hugo Duncan, says that most of the mocking tools in Clojure reflect the Java mocking libraries and don't harness more of Clojure's dynamic capabilities.  Atticus follows the convention of implementing mocking by binding a function's var to a new function for the duration of the test.  Atticus also has new support for mocking protocols.

You can find hundreds of other Clojure-related projects on GitHub such as Leiningen, Compojure, and then there's jclouds, which wants to be the Clojure cloud library.

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}