Language, Expression and Design



December 2015

think data, escape encapsulation - hara.object

by Chris Zheng,

If there was one superpower I wanted when working with java, it was to be able to visualize the object exactly the way I wanted. Fine, there was the watch function on the IDEs but that was slow and unwieldy - I had to set breakpoints and run to that particular point in time and it was such a hassle to click on the + sign to expand the object that I wanted to inspect.

Working with clojure's repl has lessened the need for inspection but I found that there was still something about working with java objects that made it such as pain as opposed to the simplicity of clojure datastructures.

hara.object attempts to bridge this gap. The library has been extracted out from gita where it was used to analyse the jgit porcelain api and to reflectively generate an interface for git. Currently libraries that rely on hara.object for exposing functionality are:

hara.object works at the level of meta-programming. As explained in the previous section, there is a correspondence between a class and the data with the class. Below shows a simple example of the concept of Dog as an Object and as data:

Notice that instead of custom getter functions, data is expressed directly as a nested map. There are advantages of using pure data for the representation of the Dog concept.

  • generic methods con be used to manipulate the data
  • the entire structure is transparent is better for reasoning
  • simpler representation (though at the cost of Type Correctness)

In this way, many objects can be turned into maps/data for consumption by clojure methods. This makes working with many big java libraries much easier before.

Documentation is up at hara [website] ( Please have a play!

comments powered by Disqus