Friday, January 7, 2011

algebraic json differences (change logs, replication, oh my)

This is a hacked-out version of an idea I've been playing with.

Since I've adopted CouchDB as my mind set, I would like to make life easier by focusing on JSON at a very general level. There seems to me a potential for some algebraic goodness with JSON. What does this mean? I don't exactly know yet. What I have so far is a non-commutative operator on a set of JSON objects. I've defined addition and subtraction. Multiplication doesn't make any sense, so I'm at the best I've got a group.

Use Case 1: Change Logs

I have an old copy of an object and now I have a new copy; I can use this code to compute a difference that will turn the old copy into the new copy. Ideally, this will enable audit logs as well as some form of revision since I can describe the entire object as a sequence of additions by starting out an empty object.

Interestingly Enough, if you design a special set of objects such that addition is commutative, then you get Google Wave and a nice level of concurrency (using an atomic journal).

Use Case 2: Undo, Redo

It's fairly easy to make a system to undo and redo changes to an object if you can study the changes abstractly from the outside rather than requiring a programmer to make notes of all changes.

Use Case 3: Replication and Optimization (REST/RPC)

If I use CouchDB and then replicate to a node.js server running Otto, then I can store a copy in node.js (or memcache) and then differentiate to produce an object that tells me how best to replicate to foreign services (like an RPC server you don't control, but you need too). Using duck-typing inspection, you can then send only the RPC commands that you need too.

Use Case 4: Algebra is oddly fun

I get joy every time I think "Oh, C++ operator overloading would make look this sooo nice". Unfortunately, I don't work in C++ any more and so I avoid that joy, but I get the joy of being able to ask questions like "Is this a group? Is it associative? Is it commutative? What is zero? What is equality?"; I'll write up my notes when I get time, but for now the code is live on github.

Concluding Thought, Ii think algebra plays a bigger role in computing than I originally thought.

No comments:

Post a Comment