views:

103

answers:

2

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?

+4  A: 

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%5Fthread/thread/4042e7a087f43c9a/a90b9bc58cc9ec3?q=data+file+group%3Aclojure#0a90b9bc58cc9ec3

Timothy Pratley
+2  A: 

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.

cgrand