Hacker News new | ask | show | jobs
by eru 5937 days ago
Wiring some S-Expressions and parsing them, would be more apt than the eval comparsion.
1 comments

That's what I do. I persist python objects into s-expressions using a c-extension module then parse and un-persist data back to python on the other side. Everyone asks me why I don't just switch to JSON. Well I might one day, I just like S-expression for now and the parser is very small, fast and was easy to implement. I even have references (like Yaml) to persist arbitrary object graphs.
Interesting. If you are working with Python-only, why have you decided against Python pickling?
One reason is debuggability. Being able to see exactly what is persisted and what goes over the wire. Pickles can drag in arbitrarily large object graphs if you are not careful and they are not completely safe from the security point of view.

However, the other reason (the original reason peraps) is that we have some C processes that listen and interpret s-expressions. There were there before Python, so we already had an s-expression library for them. Then our Python processes had to talk to the C so I implemented Python object persistence on top of the existing s-expressions. Now we use it even between Python processes.

Well perhaps one day we'll just switch to json, yaml or protobufs. But we haven't decided which one yet.

I do find it interesting that nobody even mentions s-expression these day when there compare various persistence mechanism. I guess lisp and parantheses have stopped being cool?

When the only thing you have is XML, then S-Expressions are an enlightenment. JSON isn't nearly as moronic, so there's less pain to make you reach for S-Expressions. I guess JSON is good enough.

We use S-Expressions for logging in XenServer.