Mitch Pronschinske is a Senior Content Analyst at DZone. That means he writes and searches for the finest developer content in the land so that you don't have to. He often eats peanut butter and bananas, likes to make his own ringtones, enjoys card and board games, and is married to an underwear model. Mitch is a DZone Zone Leader and has posted 2573 posts at DZone. You can read more from them at their website. View Full User Profile

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

06.21.2010
| 6132 views |
  • submit to reddit
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.

clj-ds

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

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
(atticus.mock/expects
[(f [arg]
(atticus.mock/once
(is (= arg 1) "Check argument")
arg))]
(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.

Comments

Mike P(Okidoky) replied on Wed, 2010/06/23 - 8:46am

When I see a code blurb like this, I think of my poor junior colleagues scratching their heads and constantly bugging me how things aren't working, or else they'll check in complete crap code. I doubt if these niche languages can exist outside advanced developer's interests.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.