. .


Brain Surgery While the Engine is Running

October 19, 2010 19:06:08.641

Sean Denigris explains how to do brain surgery on a bunch of existing Smalltalk objects when you make a code change:

Now comes the problem…  I had objects floating around that already contained a non-empty OrderedCollection.  I didn’t want to add otherwise-not-needed accessors.  Luckily, because of Smalltalk’s awesome reflection capabilities, it was a breeze to reach into these objects and surgically change them.

You might wonder why that's useful, but consider this situation (which I've actually had):

  • You make a code change for a running app server, such as the one you're reading this post on
  • There are existing objects that have the old object shape, and need the new object shape

Just use the same sort of strategy Sean outlines above. I've done that a fair number of times over the years, both to the servers I maintained at Cincom while I was there, and to this one. It's a really handy thing to be able to do, because it's much, much better than the more standard tack of:

  • Take server down
  • Apply change
  • Bring server back up

It works great, even in production.

posted by James Robertson


Re: Brain Surgery While the Engine is Running

[Kjell Godo] October 19, 2010 21:21:50.693

I once made a >>crystalize >>unCrystalize method pair for the same thing. You crystalize into a generic Crystal object with a Dictionary of instance variable name value pairs. Then you change the Object shapes. The new Object shape has a new unCrystalize method. So you crystalize the Objects change their shape and then unCrystalize to the new shape. But in Dolphin Smalltalk if you change the shape in certain sane ways then you can change the shape of Objects and it does the crystalize uncrystalize for you automatically. If you want to do insane shape changes then you need >>crystalize >>unCrystalize.

 Share Tweet This