I just published another version of the NamedSlot package and associated test package. The test package has 16 tests. They're a bit pedantic, but...
Once you have these things, the real temptation is to not just be able to synthesize them, but actually use them. ClassDescription uses a simple array of strings to model instance variables. And then there are a set of methods which can determine the field index from a name, or a name from a field index. So what this next version brings to the table is a couple of things:
- There are about 6 methods which reference the instanceVariables slot directly. Ideally, there would only be two, one for a setter and one for a getter. So I overrode the non-ideal ones and fixed them calling instVarNames. Simplified the code actually, because you don't have to check for nil then.
- The instVarNames now routes through the localNamedSlots accessor. That method references the slot directly, but has the ability to detect what kind is stored, and synthesize a return value if necessary.
- The instanceVariables: selector now creates NamedSlots around the string arguments.
- Finally, a method to useNamedSlots and dontUseNamedSlots on ClassDescription. There's utility methods on the NamedSlot class to convert the whole system one way or the other.
And with a few tweaks like this, it all just works. What is actually stored is transparent, the system charges one. You can just have some classes have NamedSlots while others still have Strings. Or all can be converted. Or they all can be converted back. That the system can be kept running and in tact while doing this sort of self surgery is pretty cool IMO. The pedanticism to my tests should be obvious now hopefully.
If you make the conversion, and then inspect ClassDescription, you'll see what I might call a metaslot. Because 'instanceVariables' has become a collection of NamedSlots about NamedSlots.
I've not actually tried loading this thing yet into a clean image, so I can't say how well that works.