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.

Sunday, January 20, 2008

Writing my first Objective-C program

While working on the code for a future post, I needed to write a little Objective C program. The program is very simple one but I wanted to do some string processing and use some data structures such as dictionaries an arrays.

Because of this I thought it was a nice opportunity to learn a little bit about the GNUStep project. For its home page:


GNUstep is a cross-platform, object-oriented framework for desktop application development. Based on the OpenStep specification originally created by NeXT (now Apple), GNUstep enables developers to rapidly build sophisticated software by employing a large library of reusable software components.


This framework is implemented in Objective-C and it provides a lot functionality. Collections and string handling is included with this functionality. Also a lot of documentation is available in order to get started. The GNUstep documentation page provides pointers to lots of good resources.

Installation files are available from the download page. What I did was to install the gnustep-code-devel package in my Ubuntu machine, this installs all the required dependencies.

GCC, the GNU Compiler Collection includes support for Objective-C.

With all of this installed, by could start playing with Objective-C and GNUStep.

For example here's a little program that splits a string separated by commas:


#include <stdio.h>
#import <Foundation/Foundation.h>

int main(void)
{
CREATE_AUTORELEASE_POOL(pool);

NSString* aString = @"Uno ,Dos,Tres";
NSLog(aString);

NSArray *parts = [aString componentsSeparatedByString:@","];
NSString* second = [parts objectAtIndex: 1];
NSLog(second);
return 0;
}



Also the following example uses the NSMutableDictionary and NSNumber classes.


#include <stdio.h>
#import <Foundation/Foundation.h>

int main(void)
{
CREATE_AUTORELEASE_POOL(pool);
NSMutableDictionary* dictionary = [[NSMutableDictionary new] autorelease];

[dictionary setObject: [NSNumber numberWithInt: 1] forKey:@"one"];
[dictionary setObject: [NSNumber numberWithInt: 2] forKey:@"two"];


if ([dictionary objectForKey: @"one"] != nil) {
NSNumber* value = [dictionary objectForKey: @"one"];
NSLog([value stringValue]);
}

DESTROY(pool);
}


In order to compile these programs we need to create a makefile called GNUmakefile that looks like this:


include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = Test
LogTest_OBJC_FILES = source.m
include $(GNUSTEP_MAKEFILES)/tool.make


Here source.m is the name of the source file and Test the name of the executable.

And compile it by doing the following:


$ . /usr/share/GNUstep/Makefiles/GNUstep.sh
$ make


The GNUstep.sh sets some environment variables required by the makefile.

Sunday, January 13, 2008

More information on SNOBOL

A couple of days ago Mike Radow from the SNOBOL4 user group pointed me to some very good SNOBOL4 resources.

First of all there's a SNOBOL4 Yahoo group where active discussions on SNOBOL4 and related languages take place. Also code samples and links are available from this group.

As mentioned in the previous post, one of the main resource sites is http://www.snobol4.org/ by Phil Budne.

A commercial implementation of a SNOBOL4 compiler called SPITBOL is available from http://www.snobol4.com/ .

I also learn about a SNOBOL4 IDE called TkS*LIDE. This IDE is written in TCL/Tk and it worked out of the box, in my Ubuntu machine. Here's a screenshot:



The Wikipedia SNOBOL entry is also good resource.