The cost of sending a message
Posted by Fernando Rodríguez on Jan 16, 2005; 11:44am
URL: https://forum.world.st/The-cost-of-sending-a-message-tp3372722.html
Hi,
This code is form the dolphin companion. It's a method of the Driver
class, that also understands the methods firstname, surname and name.
All of them return Strings.
setName
"Create the name from the surname and firstname.
This method is called when either of them changes."
| tmpName |
tmpName := String name.
self surname notNil ifTrue: [tmpName := self surname].
(self firstname notNil and: [self firstname notEmpty])
ifTrue: [ tmpName := self firstname, ' ', tmpName ].
self name: tmpName.
This method calls several times the surname and firstname, which
haven't changed between calls.
For someone used to VB this si a bit surprising, as using a temp
variable to cache those values is much faster than calling a method
(due to com overhead).
Is this the usual Smalltalk way? Is the cost of method calling
negligeable?
Thanks