
Means just what Java would mean by game.roll(0)

does game roll: 0 twenty times, while game roll: 0 sends the game the message roll: 0. sends the message #new to the class BowlingGame, and stores the result, a new instance of BowlingGame, in the temp variable #game.Ģ0 timesRepeat. | game | defines a temporary variable named #game. That’s not important to us right now, but we’ll see the # notation from time to time. A Symbol is a string that is guaranteed unique: Every instance of #testAllGutters is guaranteed to be identical (not just equal) to every other. In Smalltalk, that name is a “Symbol” and would often be written as #testAllGutters.

The first line, in bold, is the method name: testAllGutters. Here’s the method definition: testAllGutters I always begin with all gutter balls as my first test. There’s rarely ever a delay when you define a new method … which we’ll do right now. That means that as soon as you type something, it’s done.

Now one of the cool things about Smalltalk is that it is an incremental compiler. Click a few options for luck and Smalltalk creates the class. Right-click the TestCase class name, select New … and Class, and type the name. Click Find …, begin typing “testcase” and the find browser opens that package and class. Now to build a test, I need a subclass of TestCase, the SUnit class from which tests are built. Nothing special about this, you pop up a menu in the System Browser package pane, select New Package … and type its name. I’ll begin by defining a new Package, RonBowling.
CODE ZERO BOWLING BALL CODE
Smalltalk has its code divided into “Packages”. In aid of simplicity, I’ll tell you what I’m doing, and not take you through the details except where it’s necessary. Here, just try to read the code and see what’s going on. A references section provided later will point you to some more formal language information. Because you, the reader, may be unfamiliar with Smalltalk, I’ll be introducing the ideas of the language very gradually. It has been a while since I used VW and I can use all the help I can get.Īs always in TDD, we begin with a test. If so, drop me a line and point me in the right direction. You may also notice things that I’ve done in entirely the wrong way. Part of what’s interesting about this exercise is how much I got done in those few hours. I’ve only been working with it for a few hours. Frankly, at this writing, I don’t begin to understand all of how it’s organized. Some packages are separate and have to be brought in as needed. Its code is made up of many packages arranged in a sort of hierarchic way. I could have used any of these, but this time VisualWorks won the toss. Based on the original Smalltalk-80, this package came out of Apple and then Disney, and has some of the top Smalltalkers in the universe behind it. I like Dolphin but had other reasons for going with VisualWorks this time.
CODE ZERO BOWLING BALL FREE
Object Arts’ Dolphin is a wonderful Windows-based Smalltalk, for example, with a free but limited version. It’s quite likely the best Smalltalk out there, though there are some other important contenders. Cincom makes their complete Smalltalk system available for non-commercial use.

I downloaded Cincom’s VisualWorks Non-Commercial package and installed it on my laptop. Ruby is cool, but Smalltalk rocks, because of its very sophisticated IDE as well as the simplicity of the language. There has been all this C# stuff in my life, and what little I did in other languages was done in Ruby. I really haven’t used Smalltalk at all for a couple of years. If so, I’m starting to suspect that the Smalltalk example here might serve as a better starting point. Maybe some day we’ll do an example where we create a bowling scoring thing that could maintain running scores and such. I use this example because it’s about the right size for an hour-long Test-Driven Development demonstration in Java or C#. The program doesn’t need to score individual frames, deal with errors, or light up the beer sign.
CODE ZERO BOWLING BALL FULL
(Updated: includes changes and remarks about "=" vs "=".)Īs always, I take a very simple definition of the problem: Write a BowlingGame object which, given a legal and complete series of rolls for a full game of bowling, will produce the correct total score. My experience quickly reminded me why Smalltalk rocks. To get my chops back, I started with the Bowling Game exercise. After a long time away, I had occasion to start using Smalltalk again.
