Monday, October 24, 2005


Markov-oriented Programming

Just been looking through some code with a reasonably complex hierarchy of objects, where each object is reasonably stateful, and no comments at all (joy...). Somehow I have to make sense of all this. The following thought occured to me in the midst of this that having a 'Markov' model for object state would make this task much, much simpler - after construction of the object, any method should be applicable without having to know the history of the object (i.e. all previous method invocations). This is inspired by Markov Processes (from probability theory) that have no memory... this all seems completely contradictory to the standard OO approach, which attempts to make objects stateful. However many simple objects are effectively Markov - consider a file object, which is created/initialised with a filename. The operating system maintains a file pointer, but at any point in time it is possible to apply the read(), seek(), write() etc... methods to the object. Such simplicity would be greatly welcome in the code that I'm currently digesting: complex initialisation sequences are required, and it is necessary to perform a 'foo()' before a 'bar()'; just don't even think about performing 'baz()' until all the planets are aligned. Having formal models of object state would help. Perhaps we can all find inspiration from communication protocols (e.g. the TCP/IP state transitions), and develop simple automata models. It would be nice to give this more thought.

Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?