In the comments for this post, I got an honest question about adding "extension methods" in Smalltalk. This was in the context of an overly excited C# developer noticing the limited version of this that Microsoft provides.
In Smalltalk, we don't really have a name for doing this, because it's something natural. We've always been able to add and/or modify methods at runtime. Heck, we can add or modify existing classes at runtime - over the weekend, I modified classes in the blog server you're reading this on. In Smalltalk, there's not really a line between "development time" and "tuintime".
With Smalltalk, you can add methods, modify existing method definitions, delete methods, add new classes, modify existing class definitions, and delete existing classes at runtime. I do that in this blog server all the time, and the people reading it don't notice, unless the modification adds new (visible) functionality). When you modify a class definition in Smalltalk, things "just work" - all the existing instances in memory get modified to match the new definition. This is why I often define accessors for new attributes like this:
foobar
"get the foobar instance variable"
^foobar ifNil: [foobar := 0].
That way, it gets initialized the first time it gets requested. I could just as easily send a message to all the instances (assume the class is called FooBar):
FooBar allInstances do: [:each | each foobar: 0].
With Smalltalk, you almost never have to shutdown a running service to update it. You can do that as a matter of policy, but you can also - as I do - upgrade it in place
Technorati Tags:
dynamic languages