UPDATE: for class variable reflection, see the end
I had a class with an instance variable that required no accessors, like this:
Object subclass: #MyObject
The instance variable was initialized to hold an OrderedCollection, but after working with the object for a while, I decided that it should be a Dictionary.
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. For each object, I just evaluated:
| temp oc |
oc := self instVarNamed: 'instVarWithoutAccessors'.
temp := Dictionary new.
oc do: [ :d | temp at: d name put: d ].
And a quick inspector showed that the objects now contained a Dictionary that contained all the elements contained in the original OrderedCollection (note that I changed the class/var names in the above text to simplify the explanation):
UPDATE: to get at a class variable via reflection, try:
MyClass classPool at: #ClassVarName
In a great presentation, Alan Kay reminds us that the purpose of education in a republic is to produce citizens who are capable of critical, rational thought.
I know no safe depository of the ultimate powers of society but the people themselves; and if we think them not enlightened enough to exercise their control with a wholesome discretion, the remedy is not to take it from them, but to inform their discretion by education.
Yet no one remembers this…
[Teachers, principles and school boards] think schooling is set up for vocational training or dealing with social problems.
This is the best programming book I’ve ever read – and I’ve read them all – in C, C++, Ruby, and Smalltalk.
It’s definitely not a basic book – but it’s not complicated either (although it gets pretty deep). In fact, while the code is all Smalltalk, it’s not about the language at all. It could be called “Zen and the Art of Smalltalk”. It gets at the heart of what it takes to go from an intention to create something, in a world we don’t really understand, to a successful outcome, that is simple, beautiful, efficient, and easily evolved.
I’m still gnawing on much of it (I just finished it a few days ago), but my viewpoint on programming has irreversibly shifted and, as Alan Kay says, “Point of view is worth 80 IQ points”. I think the programming world would be a better place if everyone read this book… I can’t believe I just gave a Reading Rainbow book report. My life is complete.
I always forget how to turn on the developer tools in Etoys. It is a simple preference set, but the name escapes me, so I’m writing it down.
- Bring up the halos on the world and select the ‘Menu’ halo
- Choose Preferences
- Under ‘scripting’, disable the ‘eToyFriendly’ Preference:
And you have full access to the developer tools…