Tuesday, January 29, 2008

First Smalltalk experiences

Experimenting with a new programming language is always a nice experience. While preparing some snippets for a future post, I took some time to learn a little bit about Smalltalk. In this post I'm going to show a couple of this that caught my attention about the environment.

There's a lot of tutorials that available. The ones I use: Smalltalk Overview, Basic Aspects of Squeak and the Smalltalk-80 Programming Language, Objects, Classes, and Constructors, Smalltalk Style and Smalltalk collections. The Smalltalk implementation I downloaded was Squeak.

As a friend of mine once told me, one (of the many) nice things about Smalltalk is the way it handles the source code. No explicit files are used to store the code. It seems that the source of program and the IDE you are working on is part of the running program itself(!).

The System Browser is a key part of the Smalltalk environment. There you can explore existing class definitions and add or modify classes.

Another interesting element of the environment is a section called Workspace, where you can write some code to test the functionality you just implemented. For example I implemented a class that loads the contents of a CSV file. Here I'm creating an instance of this class, and I'm going to inspect its contents.

By calling the inspect method the inspect window let you explore the members of the instance.

Another interesting thing is that the environment itself helps you to write a correct program. For example in the definition of the following method I forgot to the declare the headers instance field. When trying to save the modifications the environment tells me that the headers variable is not declared and ask me if I want it to be declared as a local variable or as a instance variable.

The environment also inform you when a local variable is not used. For example when trying to save the following code:

The environment tells me:

This "live" programming environment is pretty nice. It seems that the Smalltalk environment was/is a strong inspiration for IDEs for other languages.

1 comment:

Tecnomod said...

very nice article! using it to go deeper into the language (i'm a delphi and php hobby programmer) the content and the links are very helpful. Thanks!