I was writing a little program to track monthly outgoings. “Only” £30/month for internet access or whatever can quickly add up …
But what format should I save the data in? XML is heavyweight and redundant compared to S-expressions, compare:
<outgoing rate="monthly"> <price>30.</price> <name>Internet</name> </outgoing>
(outgoing (rate monthly) (price 30.) (name "Internet"))
(Update: fixed XML x 2)
One difference I always notice is the redundancy of attributes like rate=”monthly”. S-expressions let you decide to make the attribute structured, but with XML you’re stuck with a simple string unless you make an incompatible change to the schema.
Another difference is that S-expressions are typed. 30 is a float and “Internet” is a string. XML is all just strings, which sucks when your language is typed.
On the other hand this article makes a good argument that XML is not (and is better than) S-expressions. More debate here.
A killer feature of OCaml is the sexplib syntax extension which makes S-expressions really easy. You just define any OCaml type in the usual way, and add
with sexp after it, and that magically generates serializer and deserializer functions for your type, so you can slurp your data into and out of S-expression files effortlessly. A page of boilerplate disappears in just two words. That’s probably the reason why I’ll go with S-expressions for this.