title: Reversing Computation Through Externalization
body: <p>I have a distinct feeling I'm getting way over my head again. A few months ago I built a system that search through code and made modifications using reflection. This worked nicely, now I'm trying to rebuild the system and generalise some aspects of it a little. One thing I'd like to do is be agnostic to the changes that might have gone on in the most recent bit of computation.</p>
  
  <p>So, for instance, let's say I'm executing a Mario program and we press a button. The game's state has changed, but we don't know how. I want to reverse this effect so I can go back in time and press a different button. My plan is:</p>
  
  <ul>
  <li>Externalize all the game classes that may have had some effect applied to them. Store the value of all non-final fields, including static values.</li>
  <li>Write out all game objects using extern.</li>
  <li>Make the change.</li>
  <li>Write out all game objects using extern (in case we want to jump back to this state later)</li>
  <li>Read the pre-change state back in again.</li>
  </ul>
  
  <p>On the face of it, is anything going to explode in my face here? Is this a sound idea? Or will some static field/strange behaviour mess me up? For externalization I am literally planning on asking for a list of all fields via Reflection and writing them out in iteration order, so as not to miss anything.</p>
  
  <p>Mods - I used the tag serialization as externalization isn't an existing tag. Hope that's ok.</p>
  
  <p>EDIT - I won't need the value of local variables, or the stack or heap just yet. This may be a  consideration later though - particularly the existence/nonexistence of objects which may have been destroyed between changes.</p>
  
  <p>Essentially, I need to reverse a general computation step. no idea if this is possible.</p>