Today's Smalltalk 4 You sketches out a case statement object in Smalltalk. Not because this is a great idea; generally, you want to use Polymorphism. However, having been asked about such a thing, we have a sketch of how to do it. 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:

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:

Recently, I was asked about Case Statements and Smalltalk - Smalltalk does not have one (nor does it need one, for the most part) - but it makes for a small, interesting example. I had created one of these in VisualWorks years ago, but it ported pretty cleanly into VA Smalltalk (the only real difference being that #new in VA does not send #initialize to the newly created instance). I have verification that the code works as-is in GNU Smalltalk as well - not a surprise, as it's pretty basic stuff. Here's the class definition:

Comments

Re: ST 4U 318: Sketching Out a CaseStatement Object

[anonymous] December 7, 2012 17:36:46.802

Would have been nice if you could have listed some cases where a case statement may be legit. Personally, I tend to use case-ish stuff for data parsing where all I have is a string or other raw value and I need to create an instance of some class from it so I can use polymorphism later.

Re: ST 4U 318: Sketching Out a CaseStatement Object

[Bob Nemec] December 10, 2012 8:42:03.461

One place I found myself using case statements was in the UI code (VA in my case). That's where the Smalltalk code is acting more like a conventional program manipulating data structures.