Smalltalk Report, November–December, 1993
Published online by Cambridge University Press: 04 August 2010
Okay, back to tilting at windmills. Sometimes I think people just don't get Smalltalk. Why in the world would you want a grungy old explicit case statement when you have a superior substitute in the polymorphic message? How could you read and write Smalltalk code for enough years to be able to implement new language features and not understand that you didn't need them?
I guess my tights and cape aren't far enough at the back of the closet…
This month's topic is case statements: practical necessity or pernicious contaminant? My interest in the topic comes from several areas at once. SmalltalkAgents has added a form of case statement to their Smalltalk for the Macintosh. CompuServe has hosted a lively discussion of isKindOf: and its relatives. Finally, net news has had a discussion of case statements. What's the deal?
Cutting right to the punch line, I think case statements are an inappropriate holdover from procedural thinking. While vital in procedural languages, their use in object programs is obviated by the much more powerful mechanism of the polymorphic message send. Anytime you find yourself wishing for or using a case statement, you have an opportunity to take advantage of objects instead. The noncase version will yield a more maintainable, more flexible, more readable, and faster solution.
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.