Object>>caseOf: (was Re: [Q] Enum style Object?)

Hannes Hirzel hannes.hirzel.squeaklist at bluewin.ch
Wed Feb 19 09:54:05 UTC 2003


Niko Schwarz <niko.schwarz at gmx.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Am Mittwoch, 19. Februar 2003 08:06 schrieb Hannes Hirzel:
> 
> > Perhaps it is easier to explain if you provide some code
> > or a specific example.
> 
> I understand him like this, at least I myself do it with symbols.
> Here's a snippet out of my jabber code:
> 
> el name caseOf: {
> 		[#stream:stream] -> [self verifyProtocol: el attributes].
> 		[#iq] -> [self channel: #iq add: el].
> 		[#message] -> [self
> 			channel: #message
> 			add: (el asJabberElementForConn: self)].
> 		[#presence] -> [self
> 			channel: #presence
> 			add: (el asJabberElementForConn: self)].
> 		[#stream:error] -> [self channel: #stream:error add: el]}
> 		 otherwise: [self error: el name asString , ' is unknown!']
> 
> Where el is kind of a "state variable". If you feel this is too undocumented, 
> and so did I, you can add a comment to the message explaining the possible 
> values of el. If it is an instance variable, it belongs into the Structure: 
> part of your class comment.
> 
> regards,
> 
> nick

Well the "traditional style" would be to do this with a dictionary of
symbols as keys and blocks as alues. You ask 

(myDict at: #someSymbol) value
or
(myDict at: #someSymbol) value: anObject

But I'm not sure if this is better than the code snippet above. At least
it is rare style.
I didn't even know that Object>>caseOf: exists!
In my current 'productive' 3.5alpha image there are only three senders
of this method:
two in MessageNode and one in MethodFinder.

Smalltalk teachers and traditionalists out there - what do you think?

Hannes



More information about the Squeak-dev mailing list