05-25-10 - State and the Web

There's a major way that the whole iPple device thing is taking us backwards. Plain old HTML (eg. not apps) is awesome in that they actually get something really right :

Minimal state. Recordable state at every transition point. This lets you bookmark your point anywhere in your work, go backwards and forwards, save your spot and come back to it, etc.

This all goes back to the entire state being a little token that you can just grab and store off. Granted, lots of web pages fuck this up because they use some server-side shit and they don't show you all the public state or whatever fucking dick-ass thing they do. But good old fashioned Web gets this awesomely right.

It's actually a paradigm that I think more developers should espouse in their Win32 apps, both publicly and internally.

By "publically" I mean you should expose it to the user - let the user drag off the current spot to a link, and let them restore. This should be in like every app. The full state of the app should be in an edit box somewhere that I can copy/paste or drag to the desktop. I should be able to double-click it to jump back into the app at that same point.

"Internally" I mean it's nice to make sure your state some very simple plain C structures, so that you can just push & pop or save old versions of the state, like :

State save(curState);



curState = save;

this is actually one of the new things I'm doing in my Video Test framework and it has been awesomely useful.

Yeah yeah the C++ way is to give every member a stream-in/stream-out, but it's too hard to maintain that robustly all the time.

This is actually related to another very important programming paradigm in general : minimize state, and avoid redundancy. Don't store variables that are computed from other variables. Don't copy values from one place to another. Always go get them at the original source. This is a massive bug reducer. Every time I see something like "this variable must be kept in sync with this variable" I think "why not just get rid of one of them?".


MH said...

Heather hit something similar recently. There was no undo for a simple and fairly obvious operation.

She got very angry, and I agree that this op should have been undoable.

cbloom said...

Oh yeah, in cases where the state of the system in question is too big to just be a little token you can copy/paste or keep a history of, you should then use a change journal.

So every app should be fully undo-able, and not just undo-able but easily jumped into any point.

So for example, the Windows Registry should use a change journal. A picture viewer should have a full state token. etc.

old rants