Question

I would like to move data back and fourth between clojure applications. Application settings and some state information.

I can not decide between using xml or s-expressions, what do you think pros and cons of each approach?

Was it helpful?

Solution

Programatically the most convenient way is simply use the print function to a file, and read function from a file. Make sure to check out print-dup read-eval if you choose this approach. Pros: simple, easy, human readable/editable. Cons: language specific.

Clojure has an inbuilt XML reader also so that is a valid choice if you have a requirement to have the data be interoperable in some way with other XML applications... but I wouldn't recommend XML unless you have a specific need for it. Pros: sometimes a requirement. Cons: ugly, extra work.

There is also a great JSON library in clojure-contrib if you want an alternative to s-exp. Pros: interoperable. Cons: extra work.

Here is a good discussion about these methods: http://groups.google.com/group/clojure/browse_thread/thread/4042e7a087f43c9a/a90b9bc58cc9ec3?q=data+file+group:clojure#0a90b9bc58cc9ec3

OTHER TIPS

If this file is for internal use only (no other program will ever need to read them) then it's an implementation detail, go with the simplest solution: s-exprs. Else, JSON or XML.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top