9 ms·
I've just built a piece of software and realized it would be a lot better if it could save/restore its state when it restarts. I already have all state isolated
by andai 4y ago
I've just built a piece of software and realized it would be a lot better if it could save/restore its state when it restarts. I already have all state isolated in state objects, but they're not plain JSON, they contain instances of classes and things like that. But in virtually all cases I could replace classes with TypeScript interfaces (i.e. just use pure JSON and still get the type-checking benefits).
There are some exceptions where classes need to be instantiated, and I'm thinking, instead of writing a bunch of ser/de, I can just make them static, Replace-All `this` to `self` and add a `self` param. Boom, suddenly save/load is a simple as JSON.stringify() and JSON.parse()
Then I realized I'd reinvented C (plain old data) and Python (explicit self param). Nothing new under the sun!