. .


ST 4U 325: Constructed Messages

December 28, 2012 11:40:35.884

Today's Smalltalk 4 You looks at constructed messages - sometimes useful in Smalltalk, but not without their risks. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Config Maps.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

One of the things you run across in Smalltalk early on - and typically think is very cool at the time - is the ability to construct and perform a message send. You can ask an object to execute a message via the symbol for the name:

someObject perform: #nameOfMethodHere

That kind of thing is common, and used quite frequently - for instance, eecuting a message after an item has been selected from a list of options. If the actual symbol is used, it's even traceable by the tools in the system. What's also possible - but much harder to trace - is something like this:

	| msg sendMsg |
	msg := lastState
		ifTrue: ['add', tail]
		ifFalse: ['remove', tail].
	sendMsg := msg asSymbol.
	lastState := lastState not.
	self perform: sendMsg

Here, a message is constructed by string concatenation, with the string then being made into a symbol and performed. The problem? It's impossible to find these references with the tools - you have to know where they are. Worse yet, we've seen such usage combined with the last screencast - wrap this in an MNU handler, and you'll never know what it isn't working.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Tags: ,

[st4u235-iPhone.m4v ( Size: 2725923 )]

posted by James Robertson

 Share Tweet This