Home
Archives
About us...
Advertising
Contacts
Site Map
 

ruby in steel

 

LIVING WITH SMALLTALK #1

Having been scarred by his experiences with languages such as C++ which bolt objects onto an existing procedural framework, Dermot Hogan takes a look at a new implementation of the classic ‘pure object oriented’ language, Smalltalk.
smalltalk
 

 

Over the coming months we shall be following Dermot's experiences as he learns to use and program Dolphin Smalltalk X6. In this first part, he puts an experimental toe into the Smalltalk waters before deciding to jump in at the deep end...

I last looked at Smalltalk a good few years ago – 1992, I think. I was considering it for use in a commercial project that unfortunately never got further than the drawing board. Before that, I’d come across Smalltalk in the fabled  August 1981 copy of Byte (which I still have incidentally. And I’m not open to offers – it’s staying firmly on my bookshelf in pride of place).

It took me a good eight or nine years from reading Byte to get to some real understanding of what object orientation was about. That was simply because I couldn’t get hold of anything that had an object in (or anywhere near) it. Borland C++ was the first tool that I came across. However, as I found out, C++ is not a good way of learning about object oriented (OO) software. A more inelegant way and error prone of doing OO is difficult to imagine. I have to agree with Alan Kay’s comment about C++ “not being what he had in mind” when he invented OO. The fundamental problem with the 'C' implementation of OO is that it is bolted onto a language that was not designed for OO.

This afternoon, I decided to take another look at Smalltalk – this time using the newly released Dolphin Smalltalk X6. I’d spent the morning writing in C – plain, unadorned 1980 style C - on a PIC microcontroller. I was struck at how well it’s suited to that task. But every time I drop into Visual Studio C++, I tend to avoid its OO features like the plague. I really dislike using such crude tools. Even C# isn’t fully object oriented – you can’t inherit an enumerated type for example.

But while musing on the OO implications of  the ++ operator, I started to think … just how easy is it to increment an integer in Smalltalk? Can something like a ++ operator be defined?

To anyone experienced in Smalltalk, that’s probably a laughably stupid question. But then as a laughably stupid Smalltalk ‘programmer’ coming to it again after a fourteen year absence, it struck me as a good question as any to ask.

So after a quick (it is quick too) installation of Dolphin Smalltalk X6, I opened a window into the Smalltalk world. And I suspect that my reaction was pretty similar to most Smalltalk neophytes: absolute bafflement. How do you even get started? Fortunately, Dolphin pops up a help window with a section right at the top ‘Newcomers start here’. So I did.


Dolphin Smalltalk X6 - a beautiful environment but baffling for a complete beginner...

The first thing is to create a ‘workspace’. Easily done, click on the Workspace icon and you’ve got one. Then following the “Splash” tutorial (a ‘pre’-tutorial really), I got a desktop clock, Windows ‘ta-da’ sounds and an introduction to function calls. Initially, I was impressed by the desktop clock demo, but on reflection, all it was doing was calling existing classes. The same could have been accomplished in C# with more lines of code, admittedly - but then again, not many more. Still, that’s carping. The Splash tutorial is good as a very basic introduction.

I then followed a fair bit of the more advanced tutorial before getting bored, at which point I decided to leap in and splash around on my own. Not with any great success I must add. I tried to derive a new class from the fundamental ‘SmallInteger’ class to implement my increment operator. No go. It took me a bit of time to figure out that Smalltalk won’t allow this, though I can do what I wanted by containing a SmallInteger in a new class.

This isn’t a criticism. For me, this is fairly typical of trying to find my way around a new language. I find that I learn a lot more from things that don’t work rather than rigorously following a tutorial in which everything goes like clockwork. What I did get, though, was a good idea of how the Dolphin environment makes it easy to create classes and associate methods with them. It really is a lovely environment to work in.


Whether you are browsing existing classes or creating new ones, Dolphin has the tool for the job...

Now – onto my real problems with Smalltalk as a language. Frankly, the Smalltalk mantra that ‘everything is an object’ gets in the way. In any good object oriented system, it’s clearly the case that everything is indeed an object. But Smalltalk forces you to think like that all the time. The saying that “If you are a hammer, then every problem looks like a nail” applies here. Not every problem can be solved by using OO techniques – databases come particularly to mind; true, there are some large OO databases around, but relatively speaking, rather few of them. I find it particularly annoying that Smalltalk takes OO to the extreme, in that the expression 1 + 2 * 3 evaluates to 9 and not 7 as you (ok - I, then) might expect. Compare and contrast Ruby (another OO language): Ruby gets it ‘right’ while Smalltalk with its strictly linear “message” metaphor doesn’t.

I’m going to continue my experiments in Smalltalk not because I want to use Smalltalk for a serious application (yet), but because there’s a host of good ideas in there waiting to be exploited and I want to play around. It really is fun. And I have to say again that Dolphin is a very nice place indeed to work and play in Smalltalk. Once you get the hang of it, it’s a good bit easier than Visual Studio. I think I’m going to enjoy messing around in Smalltalk over the next few months.

Dolphin Smalltalk X6 Professional costs $475 from Object Arts http://www.object-arts.com. There is also a Community Edition available free of charge. For a bit of Smalltalk history, see the Bitwise Smalltalk Programming Milestone. For an introductory tutorial, see our Beginners' Guide to Dolphin Smalltalk.

 

February 2006

 


Home | Archives | Contacts

Copyright © 2006 Dark Neon Ltd. :: not to be reproduced without permission