SmallTalk @ FP

I’ve just had a group introduction to Smalltalk. Piers was visiting Brighton and decided to teach us all about the roots of OO programming. In lieu of the usual 5-minute-on-keyboard sessions, Piers gave us a walk through of developing kata 4 in smalltalk.

This was a superb way to learn the language. There was more heckling than usual, but that was an important and necessary part of the process in this case. Watching smalltalk in action is absolutely necessary—it’s just such a visual experience (compared to regular programming languages, anyway). I now completely understand the smalltalk credo I’d read about: just type in what you want to happen, hit “run test” and when it breaks, write the code in the debugger window that pops up.

Just before half time, Piers started pairing properly. That was when the language differences really started to hit home. Smalltalk is so not an algol-influenced language. In particular, I adore the cascade:

  fromRow: aString
    ^ self basicNew;
      initialize;
      setRow: aString;
      yourself.

That semicolon is calling methods (sorry, passing messages) to the same object after each semicolon. The statement is only terminated with a period. Conceptually, it feels similar to Perl’s $_ (or “it”).

As usual, we didn’t get particularly far in the task, but we did learn a huge amount. A big thanks to Piers for visiting us and also to Devi for cat-herding in Joh’s absence (and doing an excellent job of keeping us on-topic).

Now, I’m off to download Squeak

One Comment to SmallTalk @ FP

  1. Piers Cawley says:

    That cascade could be indented a little more clearly:

        ^self basicNew
            initialize;
            setRow: aString;
            yourself.

    You’re sending initialize, setRow: and yourself to the restult of self basicNew, and returning (^) the value returned by the last message in the cascade (ie, yourself).

    The cascade you wrote the in the main article was sending basicNew, initialize, setRow: and yourself to self, which isn’t quite what you wanted.

    I’m glad you enjoyed it.