September 16, 2003

## Smalltalk

Many of you probably have not heard of Smalltalk, since it isn't on the list of "2003 Ten Sexiest Programming Languages". Those of you that have probably assume it is an old dinosaur like FORTRAN.

While it certainly isn't in as widespread use as Java or C/C++, it has many great features which are far from being antique. (Hey, kind of like OS/2)!

Smalltalk has the distinction of being the 2nd object-oriented language created (the Simula family being first), and today, it is still one of the few purely objected-oriented languages around. (Everything is an object in Smalltalk. You don't print a string, you ask a string to print). It is even on its way to becoming an ANSI standard.

This isn't going to be a tutorial on Smalltalk (I'm not good enough for that, and there are plenty of good tutorials free on the web, and if you're new to programming, Smalltalk is as good a language as any to get started with). I just want to let you know that Smalltalk exists, and what sort of tools are available to you. And I'm sure you've heard enough from me about this, it's free to try. Both of these tools I'm going to briefly go over are freely downloadable.

### Why Smalltalk?

Don't use it because it's object-oriented or just to be different. Use it because it's fun! I remember my first classes in Smalltalk, after the initial hurdle in grasping the concept of full "object-oriented-ness", it was actually fun to program in Smalltalk (if you could call any programming fun). Lisp/Scheme is not fun. C is definitely not fun. Java and Smalltalk are pretty fun.

Once comparison I might like to make when talking about Smalltalk vs. some of the "hot" languages today, is the same thing I might say about Rexx vs. Perl. Both are powerful, both have their strengths and weaknesses, but Perl allows you to produce code like this:
`s/TS:.*?\0/$_=$&;y,a-z, ,;s, $,true,gm;s, 512,2048,;$_/es`

That was a one-liner from the Perl Journal that patches Netscape to enable strong encryption. For even more fun, look at the winning entries to the Obfuscated Perl Contest's. There's similar contests for C. But not Rexx. And not Smalltalk.

And that's a good thing! I don't know about you, but trying to debug or maintain code that could look like that is definitely not fun. (I should stress that it doesn't have to look like that, but it could. With Rexx or Smalltalk, you're practically forced to produce readable code). Here's a sample snippet:
`| anArray anIndex aValue |
aValue := 2.
anArray := Array new: 10.
1 to: 10 do:
[:index |
anArray at: index put: (aValue * index)].
anIndex := 1.
[anIndex < anArray size] whileTrue:
[Transcript show: 'Value at: ',(anIndex printString),' is ',
(anArray at: anIndex) printString ; cr.
anIndex := anIndex + 1.]
`
Alright, so it isn't exactly poetry, but once you know the syntax, it is easily readable. (At least compared to a lot of C/C++ code I've seen).

Though Smalltalk is not a toy language, it was originally tested on children. The developers figured that children have such a short attention span that if they could keep their attention, it would be a good measure of the ease of use.

In fact, I think most Smalltalk development environments allow you to alter code on the fly. Just run the program. Don't like how it's working? Change the code and watch the program change before your eyes without recompiling.

Now lucky for you, OS/2 hasn't been left out of the Smalltalk arena. We have at our disposal a couple of the more well-known implementations and they are even up to date!

Please note that I am not an expert in either of these products, I'm still learning them myself, so if you see any inaccuracies or errors, please forgive me in advance.

### Squeak 3.5

Squeak is an implementation of Smalltalk-80, basically the current Smalltalk standard. It actually originated with a group of people, and at least one of the originators of Smalltalk itself, Alan Kay. It is freely available (as in no-cost and open source) and has been ported to many different platforms, one of them, of course, being OS/2. And no worries, the OS/2 version is up to date, with the latest release being just April 2003.

Squeak works a little bit like Java actually. There is a platform-dependent virtual machine used for development, and then there are just 3 other platform-independent files required (sort of like the Java class files).

### Installing Squeak

As mentioned, you just need 4 files, totalling less than 11MB compressed. (But note that the Image file and the Changes file are actually packaged together in one `.ZIP` on the FTP site).

1. The OS/2 Squeak VM (http://webs.sinectis.com.ar/jmvuletich/SqueakForOS2/SqueakOS2VM.zip)
2. Squeak V3 sources (ftp://st.cs.uiuc.edu/Smalltalk/Squeak/3.5/SqueakV3.sources.gz)
3. Squeak 3.5 Image (ftp://st.cs.uiuc.edu/Smalltalk/Squeak/3.5/Squeak3.5-5180.zip)
4. Squeak 3.5 Changes (ftp://st.cs.uiuc.edu/Smalltalk/Squeak/3.5/Squeak3.5-5180.zip)

You need to make sure you have the following requirements:

- Long-filename support (e.g. HPFS) and at least 32MB free disk space. The files uncompress a lot.
- DIVE support
- DART support
- At least 256 colour video mode

Oh, and you'll probably want to use a 3-button mouse unless you want to emulate 3-buttons with key and mouse combinations. This doesn't mean you'll need a special mouse driver. I just use the IBM supplied mouse driver and a scroll-mouse and it works just fine.

Unzip all the files into one directory and that's it. No need to do anything else. No messing around with `CONFIG.SYS` or re-booting or anything. To run Squeak just use `SQUEAK.EXE`

### Squeak Environment

If you've got all the necessary files, Squeak should load up in its own window. Don't worry about the look and colours. It's all part of a "theme" and is customizable if you think this looks too cartoony.

You'll find various tabs all around the window which you can click on to pop out toolbars. The amazing thing about this development environment is that it is completely written in Smalltalk itself. It's sort of like writting a Java IDE in Java (like Simplicity (http://www.datarepresentations.com)).

Now before you get all frustrated and give up on Squeak, read a tutorial first! (And learn a bit of Smalltalk in the process). The interface is actually not bad to use as a visual designer. Want a button, a slider or just a text label? No problem, just drag it off the "Supplies" toolbar and on to the work area. There you can re-size it, change the colour, text or whatever and add code to it (if applicable). Those of you used to visual designers like the ones in IBM's VisualAge products may find this familiar.

All you have to do is drag and move things around until the "interface" is just like you want it, and then whip up the code necessary to run the application. It makes development a little bit easier and quicker.

### Performance

The performance of Squeak wasn't an issue for me. My test machine was a PII-300MHz laptop that ran OS/2 Warp 4.5 (MCP2), so adjust expectations accordingly. It loads up really quickly, maybe just 2-3 seconds.
I tried playing with the included, simple paint application (just drag 'n drop to start), and it seemed okay. Multi-task? Yes. In fact I started a simple "bouncing atom" animation demo in Squeak and proceeded to play with the other tools (MPEG movie player, sound tool, etc.), all the while, my system is still running SETI@HOME and other apps and it was still pretty good.

### Producing your own Applications

Now here is a weakness or a strength of Squeak. It currently doesn't have any facilities to compile a native executable of your application. Everything must be run through the Squeak Virtual Machine (VM). All you do is use the "publish" facility so that your project can be used by other people.

The bad? You don't get a nice, single OS/2 executable as you might expect from developing a true "native" OS/2 application. Users will have to get the VM themselves and run your application.

The good? Well, it's just like Java, isn't it? And Java application development and use seems to be faring not too badly. It means you can develop one Squeak application and have it run cross-platform. For OS/2, the VM is less than 700kb anyways, so it isn't a big penalty to package it with your application itself.

Developers are working around it. Mac users have a curious trick to store the VM and the application in the separate resource forks so it looks like one executable to the user. OS/2 also has EA's which may be possible to use in a similar manner. Another way that might work, the most straightforward way, is just to package the Squeak VM and use your application as the Squeak Image. (Remember, the IDE is written in Smalltalk and there's no reason the "IDE" is actually your application). I'm sure there are several other ways to deal with this, so you should probably just read the tutorial and documentations.

### Conclusion

Squeak is a nice, easy way to get started with Smalltalk. Even though it is free and friendly to use, it's also powerful enough for serious applications. (It is Smalltalk, it isn't a toy). Once you get used to Smalltalk, Squeak can be an invaluable tool for real rapid-application-development (RAD). Did I mention it is absolutely free and open-source too?

### IBM VisualAge Smalltalk

The latest version of IBM's Visualage Smalltalk is v6.01, which is available on many platforms including OS/2. For commercial use, it'll cost you several thousand dollars. (Didn't I tell you? Smalltalk isn't a toy language!).

But luckily for us (and some of you may have read the post from one of IBM's Smalltalk developers), it is now free for non-commercial use. Forever. All you have to do is go download it. Just a warning, the site is a bit confusing. What you want to download is the v6.01 Fixpak. This is actually a full working version of VisualAge Smalltalk that doubles as a patch to v6.00. If you have purchased v6.00, the v6.01 patch updates your installation and keeps it "registered" as a commercial, purchased version. If you don't have v6.00, it stay as a trial product, with no expiration date and all features. The only difference being a "nag" screen.

### Installation

There are 3 packages for download from IBM. You should probably get all 3, but I think at the very least, you need to get the Client package (of course) and also the Manager package. Expect to use up about 85MB of disk space just to download the compressed packages.

The next thing you should do is unzip the Client and Manager and run the installation program. (I recommend you should probably install the Manager first and then the Client, as the Client installation will need the installed location of the Manager. Otherwise, you'll have to remember where you told the Client where you said the Manager will be and install accordingly). It isn't the standard IBM installer nor is it the Feature Installer, but it is a nicely done, professional looking installation (which uninstalls nicely too).

I don't know what it is with these Smalltalk packages, but they expand enormously! You will need somewhere around 72MB for the Client and 192MB for the Manager! Note that for the client, at installation time, you have the option of specifying whether you are working in a "team environment" (the Manager libraries sit on a server) or stand-alone. In either case, you still need to install the Manager component.

### Using VisualAge Smalltalk

My test machine for for this was an old K6-II 350MHz that ran eComstation. Performance was not a problem, not did I run into any memory issues (I have 256MB installed). But to be fair, I did not push it a lot yet. Your mileage may vary.

Those of you used to IBM's VisualAge series of products should find the interface very familiar and easy to use. Those of you who haven't tried it should give it a spin, just so you know what a "visual" programming tool can do.
Yes, this is IBM's very familiar visual composer, which, if I recall correctly, has a similar version for VisualAge Java and VisualAge C/C++. You just select the item from the menu on the left and click to place it where you want it.

"Programming" can be done by connecting each of the various parts. For a very simple tool, it's possible you may not have to type in any code at all. Usually, this is not the case, of course. Nevertheless, I first encountered this interface in IBM's Java product and I really find it makes things a lot easier for me than just straight out code.

Each object that you have in your program can be easily modified simply by using the object properties dialog.
For example, you can specify different colours for buttons, or limits on sliders, checkbox items, etc. All the code will be generated for you when you compile the application, but best of all, for most of the visual components, you see the change right on your screen, instantly.

On small projects, it's easy to handle. But for large projects, as you can imagine, the screen can get quite cluttered and objects may be hidden behind each other. Fortunately, there is a "Parts List" available.
As you can see, each item is listed, grouped by a hierarchy as befits an object-oriented programming tool. An icon and a name is listed for each one, making it easy to find the object you want. (Which means, of course, you should try to name your objects in a meaningful manner, instead of leaving it at the default name as I have done in this example).

There's a lot more that can be said about VisualAge Smalltalk, but I'm hardly the one to talk about that. You can explore that yourself or read the documentation.

One thing that VisualAge Smalltalk has going for it is the ability to produce a a standalone executable. There's a couple of simple preparation steps to follow (mainly just ensuring you'll be building with the right version of your code) and it's as easy as selecting the "Make Executable" function. So yes, you'll get a real, native version of your application for OS/2. (Yes, you can even implement some sort of drag 'n drop functionality).

### Help and Documentation

Help is provided by the "new" IBM standard. Which is not as good, in my opinion, because gone are the `.INF` help files that were the OS/2 standard. Instead help is via HTML files, which requires your browser and a loopback network interface to be setup (done automatically at installation). I guess it sure makes it easier for IBM to produce cross-platform documentation though.

On the good side, there is a lot of detailed and free documentation available directly from IBM. At the IBM Smalltalk page, while you are downloading VisualAge Smalltalk itself, you might as well grab the `.PDF` documentation, which includes nice "Getting Started" guides and other references. You can also head on over to IBM's Redbook site to download more free books on developing applications for VisualAge Smalltalk.

### Conclusion

IBM VisualAge Smalltalk is a whopping big application, but it is definitely full-featured. If you want to learn Smalltalk or produce your own custom applications, it's not a bad choice if you can put up with the nag screen (there are no legal issues here).

It has the advantage in that in can produce stand-alone applications, and it has a lot of well-written supporting documentation which are also freely available. The "Getting Started" guide is extremely useful, stepping you from the beginning right to making and producing a simple application.

Give it a shot. I'm sure if more users of Smalltalk appeared, IBM would consider changing the price structure a bit for commercial versions. Until that time occurs, you're free to keep on using the "evaluation" of this really good application development program.

### Related Links

Squeak for OS/2 (http://webs.sinectis.com.ar/jmvuletich/SqueakForOS2/SqueakForOS2.html)
Squeak Home Page (http://squeak.org/)
IBM VisualAge Smalltalk (http://www-3.ibm.com/software/awdtools/smalltalk/)
IBM Redbooks (http://www.redbooks.ibm.com/)

Isaac Leung
(P.Eng.) got a degree in Engineering Physics followed by a Master's in Electrical Engineering after which he promptly got a job as a product engineer at a company which makes high speed datacom chips. Following the dot-com meltdown, he's back at school studying biophysics and optical properties of semiconductors. He is old enough to have cut his computer teeth on Commodore 64's and first played with OS/2 1.3 EE while at a summer job with IBM. The first PC he ever owned came with Windows 95, but he soon slapped on OS/2 Warp 3 and has been Warping ever since. In between looking for a new job, he plots to take over the world.

This article is courtesy of www.os2ezine.com. You can view it online at http://www.os2ezine.com/20030916/page_2.html.

Copyright (C) 2003. All Rights Reserved.