Title: Selfish - a new message send for Smalltak
Speaker: John Aspinall
Video: https://www.youtube.com/watch?v=sjw4D9RZ9I8
Mon, August 18, 11:00am – 11:15am
Abstract: This presentation is a combination of experience report and a not-entirely-serious (but also not-entirely-silly) suggestion for a new type of method send for Smalltalk.
The presentation begins with a description of the implementation of a new form of Method Overrides for Cincom's VisualWorks Smalltalk. In this case "Overrides" refers to the replacement of one implementation of a method by another from an alternative package (Cincom's terminology for their own equivalent functionality). For reasons that will be explained, the standard Cincom implementation of overrides was not suitable for this particular project.
The presentation describes the advantages of this alternative implementation and a potential complication which was solved by the addition of a new type of method send - the "selfish" send. The purpose and implementation of the selfish send is the main focus of the presentation.
Bio: I have been working with Smalltalk since 1992, initially in academia and subsequently in a variety of employed and self-employed positions, covering all major commercial Smalltalk dialects. From 2000 to 2005 I ran my own company creating bespoke systems for SMEs using Dolphin Smalltalk; this led me to develop a number of tools and frameworks for Dolphin, most notably ReStore, an active record-style relational database interface. Since 2005 I have been employed at JPMorgan on their Kapital system, one of the largest and most long-lived commercial Smalltalk systems.
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Selfish: a new method send for smalltalk
1. selfish – a new message send for Smalltalk
John Aspinall – JPMorgan Kapital Project
2. selfish – a new message send for Smalltalk
• Kapital
– JPMorgan risk-management system
– Since 1994 (20th Birthday this month!)
– VisualWorks Smalltalk + GemStone
• ENVY source code management
– Same as VA Smalltalk
– Used under licence
– Maintained and enhanced in-house
3. selfish – a new message send for Smalltalk
• Method Overrides
– Not the same as subclass method overrides!
– VisualWorks concept
– Replaces current version of a method with a
different implementation from another Package
– Increasingly used in non-core/add-on Packages
4. selfish – a new message send for Smalltalk
• Method Overrides for ENVY
– Create _override_method in class extension
Application (Package)
– Replaces implementation of method in class’s
method Dictionary
– Original implementation stored at:
#_overridden_method
– Overridden implementation can still be invoked:
self _overridden_method
5. selfish – a new message send for Smalltalk
• Example – Adding a guard clause:
_override_method
self shouldUseOriginalImplementationOfMethod
ifTrue: [self _overridden_method]
ifFalse: [self doSomethingElse]
6. selfish – a new message send for Smalltalk
• ClassA
doThing
self doThingA
• ClassA subclass: ClassB
doThing
self doThingB.
super doThing
7. selfish – a new message send for Smalltalk
• ClassA
_override_doThing
self doAnotherThing.
self _overridden_doThing
• ClassA subclass: ClassB
doThing
self doThingB.
super doThing
8. selfish – a new message send for Smalltalk
• ClassA
_override_doThing
self doAnotherThing.
self _overridden_doThing
• ClassA subclass: ClassB
_override_doThing
self doYetAnotherThing.
self _overridden_doThing
9. selfish – a new message send for Smalltalk
• ClassB new doThing
_override_doThing [ClassB]
» self doYetAnotherThing
» self _overridden_doThing
» self doThingB
» super doThing
_override_doThing [ClassA]
» self doAnotherThing
» self _overridden_doThing
10. selfish – a new message send for Smalltalk
• ClassB new doThing
_override_doThing [ClassB]
» self doYetAnotherThing
» self _overridden_doThing
» self doThingB
» super doThing
_override_doThing [ClassA]
» self doAnotherThing
» self _overridden_doThing
...recursive loop!
11. selfish – a new message send for Smalltalk
• What do we actually want to do?
– Invoke the implementation of
_overridden_doThing in ClassA
– i.e. the implementation in the class of the
_override_ method being executed
– Not (always) the same class as the receiver object!
12. selfish – a new message send for Smalltalk
• The Solution – “selfish”
– It’s “a bit like self”
– It’s a “selfish” send
• The Implementation
– A new bytecode? Difficult...
– An existing bytecode? Easier.
13. selfish – a new message send for Smalltalk
• The (meta) Solution – “super”
– It’s “a bit like selfish”
– Invokes the implementation in the superclass of
the current implementation:
<44> push self
<1C> push {current method’s implementing class}
<F2 01> super send method
– Just need to push a subclass instead:
<1C> push (Class new superclass: {current method’s implementing class})
14. selfish – a new message send for Smalltalk
• ClassB new doThing
_override_doThing [ClassB]
» self doYetAnotherThing
» selfish _overridden_doThing
» self doThingB
» super doThing
_override_doThing [ClassA]
» self doAnotherThing
» selfish _overridden_doThing
» self doThingA
...success!