[ | smalltalk dot org ].
Community and industry meet inventing the future.
The Essence of Smalltalk
Smalltalk and it s usage in Microsoft s .Net
Written by Aditya Dutt, aditya_db at yahoo dot com

Smalltalk was one of the first systems to pioneer the WIMP (Windows, Icons, Menus and Pointers) interface. Compared to conventional programming languages such as C or Pascal, Smalltalk has an unusual syntax. Objects are employed to represent everything in Smalltalk, including all the conventional data types that may be found in any programming language: such as integers, Booleans, floating-point numbers, characters, strings, arrays. In addition to this, objects are used to represent display items such as menus, windows and even the compiler itself. Smalltalk is therefore described as a uniformly object-oriented language. Smalltalk language was developed at the Xerox Palo Alto Research Center in 1970s, the programming environment greatly influenced the development of Apple Macintosh and Microsoft Windows. Cincom has an extended version of Smalltalk-80 called VisualWorks (derived from the original ParcPlace version), which provides window-building facility and database connectivity.

IBM's VisualAge is a development environment designed to support the easy creation of software applications on multiple platforms. IBM Smalltalk provides a platform-independent application program interface (API) based on industry standards.

VisualAge Smalltalk Enterprise V6.0.1 allows for incremental and rapid development of new Smalltalk applications. Developers can build and deploy enterprise Web service solutions for dynamic e-business using VisualAge Smalltalk. Communication transactions can be protected with Secure Socket Layer (SSL) support.

Comprising nine subsystems, it encompasses the functionality required by most Smalltalk applications. Applications programmed entirely in accordance with the Smalltalk interface specification run without modification on all supported platforms, yet adopt the native look and feel of the particular platform. This enables applications to be produced from a single code base across multiple platforms, while still providing a high degree of platform integration.

The nine subsystems are of VisualAge Smalltalk are:

1) Common Language Data Types: The Common Language Data Types (CLDT) subsystem contains the classes and associated methods for working with standard Smalltalk objects such as Collection, Magnitude, Boolean, and Stream.

The Common Language Data Types subsystem (CLDT) provides a platform-independent interface and implementation for the basic data types that form the building blocks of the Smalltalk programming environment. The CLDT classes have been grouped into seven categories: Boolean, collection, magnitude, graphical, stream, support, and exception handling.

2) Common Language Implementation: The Common Language Implementation (CLIM) subsystem contains the classes and associated methods which, together with the virtual machine, implement the Smalltalk class and message mechanisms.

The Common Language Implementation (CLIM) subsystem provides a platform-independent interface that is primarily intended to describe the shared behaviour of IBM Smalltalk classes. A class in Smalltalk is an abstraction that describes a kind of object. One of the fundamental symmetries of the Smalltalk environment is that every object is an instance of a class. That includes classes themselves, which are instances of special classes called metaclasses.

3) Common Process Model: The Common Process Model (CPM) subsystem contains the classes and associated methods that facilitate the execution and arbitration of multiple execution contexts, or Smalltalk processes.

The Common Process Model (CPM) subsystem provides a process model (shared memory threads) for IBM Smalltalk. Standard operations include process creation and destruction, as well as process scheduling operations including suspend, resume, and change priority. Simple synchronization mechanisms are provided by semaphores.

4) Common File System: The Common File System (CFS) subsystem contains the classes and associated methods for performing file and directory operations.

5) Common Graphics: The Common Graphics (CG) subsystem contains the classes and associated methods for performing low-level graphics operations, such as drawing lines, circles, and rectangles and for manipulating device independent images, fonts, and colors.

6) Common Widgets: The Common Widgets (CW) subsystem contains the classes and associated methods for constructing application user interfaces through the composition of user interface components called widgets.

The Common Widgets (CW) classes and methods subsystem enables developers to design and build graphical user interfaces using an application programming interface (API) based on OSF/Motif. Using the Common Widgets subsystem, developers can do the following:

  • Create individual widgets, including buttons, lists, text, menus, and dialog boxes

  • Create compound widget structures by combining individual widgets

  • Specify the positioning of widgets relative to each other

  • Program operations to occur in response to user actions

7) Extended Widgets: The Extended Widgets (EW) subsystem contains the classes and associated methods for expanding on graphical user interfaces built using the Common Widgets subsystem.

The Extended Widgets classes and methods enable application developers to expand upon the graphical user interfaces built using the Common Widgets (CW) subsystem.

8) Drag and Drop: Through the Drag and Drop (DD) subsystem, pluggable drag and drop support is provided for the widgets in both Common Widgets and Extended Widgets subsystems without requiring modifications to the widgets. The Drag and Drop subsystem uses the portable CG and CW subsystems.

9) Common Printing: The Common Printing (CP) subsystem contains the classes and associated methods for performing printer job and page control, setup, and graphical and text output.


IBM Smalltalk directly utilizes the native functionality provided by each platform. IBM Smalltalk emulates API functionality not directly supported by a particular platform in order to support a complete and consistent interface across all supported platforms. As part of the implementation of IBM Smalltalk, access to platform-specific functionality is also provided.

Object oriented Programming languages use message sending as performing operations. If the receiving object understands the message it has been sent, then one of its internal operations will be performed. This in turn, cause some computations and a result is always returned. For instance, we are sending a message +3 to an object integer 9. Here '+' is a selector and 3 is an argument. The result of sending this message +3 to the object integer 9 is 12.

A message expression comprises a receiver, a selector and some arguments. Keyword messages are complex type of message.

 (3 raisedTo:3) raisedTo:3 is a keyword message. raisedTo: and raisedTo: are keywords and numbers 3s are arguments. Keyword ends with a colon.

We have different types of variables are provided in Smalltalk language: Temporary variables, Class variables, Instance variables, Global variables, Pool variables. By convention, private variables(instance variables, temporary variables) start with an initial lower-case letter, where as shared variables (class variables, global variables, pool variables) start with an initial upper-case letter.

In most conventional languages, array is the only sort of collection, in Smalltalk we have two types of collections: unordered collection and sequential collection. The concept of block closure is a great feature that gives Smalltalk a great advantage. It's missing in languages like C# and many other languages.

In Smalltalk we have hundreds of classes and thousands of methods. The Smalltalk is written almost entirely in Smalltalk  a small kernel is written in machine code.

I want to introduce a few concepts of the Smalltalk syntax to help the non-smalltalker to understand the issues:

Messages

A Smalltalk programmer can also invoke methods in an object like a C# programmer. The mechanism of doing so is by sending a message. Compare this with an example:

Say, the 'Printer' is a variable and is called the 'receiver' in Smalltalk.

C#

Smalltalk

Printer.on();

Printer on.

The word 'on' is called the message - it causes the Smalltalk system to locate the method with this name and to execute it. If the receiver does not have such a method, the #doesNotUnderstand: method is activated. Every Smalltalk object has this method.

Using an argument: - say, we want to set the height to the Object  Box .

C#

Smalltalk

Box.height(10);

Box height: 10.

The message used here is #height:. The colon at the end of the message is called a keyword message and it indicates that it takes an argument.

Using multiple arguments  say, we want to set the height and width to the Object  Box .

C#

Smalltalk

Box.heightAndwidth(10, 20);

Box height: 10 width: 20.

This is of only one keyword. It is #height:width:. Unlike other languages the parameters are written right after the two colons. This may seem wierd but it actually makes code that is well readable.

Control Structures

Smalltalk doesn't have control structures. Take a glance this by an example:

C#

Smalltalk

if (a > b)

a = a - b;

else

a = a + b;

(a > b)

ifTrue: [ a := a - b]

ifFalse: [ a := a + b].

We have here the receiver (a > b).

The receiver is an expression. It will be evaluated at execution and will return either the  class True) or the  class False . This object will then be send the message ifTrue:ifFalse: with the trueblock and falseblock as arguments.

Both the True class and the False Class are subclasses of the class Boolean. They both implement the method for ifTrue:ifFalse:. In the True class the first block is evaluated, in the false class the second block is evaluated. Thus the semantics of the if-then-else concept are implemented, without the language having if then or else as keywords and therefore no formal control structure exists. While and for loops are implemented in the same manner.

Blocks

A block represented by a sequence of expressions, enclosed by square brackets. Blocks are anonymous methods. For instance:

aBlock := [a := 0].

aBlock value

aBlock receives the message value, its message expressions are evaluated, here causing the variable  a to refer to the integer 0.

A Block represents a deferred sequence of message expressions.

Eg: [answer := Float pi/16]

Blocks are used as arguments in the conditional selection and control structure.

ifTrue: aBlock

ifTrue: trueBlock ifFalse: falseBlock

Sample Example for using Blocks

Sum of integers using whileTrue


|sum x|

sum := 0.

x := 0.

[x <= 100] whileTrue: [

sum := sum + i.

i := i + 1

].

sum

A block can be activated with the value message. There are a number of them that are needed to supply the arguments for the block's parameters. So a block without parameters is activated by:

[<statements>] value.

A block with 2 parameters is:

[:arg1 :arg2| <statements>] value: <arg1> value:<arg2>.

and so on/

Smalltalk with .net: Development of S#:

We got S# from Smallscript which is a redesign of Smalltalk Language.

The S# language implementation (pronounced s-sharp) is a complete modular redesign of the Smalltalk language, offering transparent cross-language integration and component based deployment. Capable of supporting both repository and industry standard file-based source code management, it offers a rich array of streamlined features which enhance the Smalltalk language.

In contrast with a variety of other programming languages, its unique modular composition technology with multi-threaded C-like-performance of dynamic and scripting languages addresses many of today's most difficult fragility and versioning challenges that developers face when working on just-in-time integration within client and server applications.

Design work and implementation of the Smallscript System began in 1999. Today, it offers modular deployment as a small-footprint, hi-performance, pre-emptive multi-threaded jit-based execution engine for dynamic and scripting languages.

It is designed to meet today's challenging requirements for building and deploying software engineering solutions as mixed language components. It enables delivery of programs and components as small as 2KB, supports namespace partitioned access to multiple co-resident versions of the same methods for a given class, and provides key features such as optional strong typing and file-based development.

It breaks new ground for developers on leading Web and Internet technology platforms such as Microsoft .NET, where it offers unique capabilities that include enabling extension of final/base classes and new patterns of reuse through concrete interface implementations. Its state-of-the-art design removes the constraints of classic Smalltalk while offering lightweight scripting and module facilities that scale up into the traditional space occupied by classic Smalltalk. It's execution and object model facilities are designed around a unified architecture of state-of-the-art dynamic language techniques including selector namespaces, optional dynamic typing, multi-methods, concrete interfaces/mixins, and self-marshalling transparent foreign functions with typical FFI calling rates in the many 10's of millions calls/sec.

Working in direct collaboration with Microsoft since 1999, the S# compiler architecture was extended to support the generation of native Microsoft.NET Framework IL modules and assemblies. Key features of the Agents Object System's [AOS] dynamic language platform facilities were also extracted and ported to Microsoft's .NET Framework to add an extended range of dynamic and scripting language services to Microsoft's .NET Framework Runtime. Smallscript provides a valuable development environment on the .NET Framework and offer developers of Smalltalk a productive, reliable, easy-to-use platform for building and deploying cross-language applications and Web services."

The S# language derives its rich object model from the AOS Platform Architecture on which it is designed to execute. That architecture was designed from its inception to support multiple languages and distributed system agent services.

While it is simplest to view S# as a single language, it is in fact only one language layer designed to integrate symbiotically within the multi-language architecture of Smallscript. The primary script structuring and object model language (AML) is the declarative meta-language of the Agents Object System [AOS CDLR]. Its declarative form is transparently mapped onto the dynamic MOP services of the execution engine to support specifying code structure and object model entities. It offers a flexible set of syntax ranging from pure XML to various more human friendly forms.

The secondary layered languages, such as S#, are generally used for writing the method bodies and describe programmatic expressions for evaluation. The language infrastructure allows any or all object model operations to be written in some other language by switching to some other alternate AOS compatible compiler; AML provides directives to switch compilers for processing directly embedded or include-referenced-code.

The Smalltalk implementation, S#, within the Smallscript family provides numerous semantic and syntactic extensions to enable transparent inter-operability with other classic languages, the AOS object model, and human programming experiences.

The Object Oriented Programming Feature Comparisons Table

features 

Smalltalk-80

S#
(SmallScript Corp's Smalltalk-98 Dialect Superset)

C#

Typing

dynamic

dynamic

static

Dynamic binding

Implicit

Implicit

yes

Root class

Object

Object

Object

Receiver name

self

self

this

Private Data

yes

yes

yes

Private methods

yes

yes

yes

Runtime access to method names

yes

yes

yes

Runtime access to class names

yes

yes

yes

Runtime access to instance variable names

yes

yes

yes

Metaclasses

yes

yes

no (classes and methods are not objects)

Inheritance

single

multiple

single

Instantiation

Explicit

Explicit

Explicit

Binding (late/dynamic)

yes

yes

no

Multi-methods (overloading)

no

yes

yes

Forwarding (Delegation, Distributed Objects and Proxies)

yes

yes

yes

Access to super method

super

super , Superclass:super, thisContext, CallNextMethod,...

yes

Class Variables

yes (classes are objects, shared/pool variables also exist)

yes (classes are objects, shared/pool variables also exist)

yes (static only, classes are not objects)

Interfaces

no

yes (supports COM model, .NET model, interfaces can define methods with code, and have concrete fields)

yes (but not instantiatable, cannot contain implementation)

Templates

no

no

no

Garbage Collection

yes

yes

yes

Pre-emptively Multi-threadable (native threads?)

no

yes

yes

Intrinsic Exception Model (native exception integration)

no

yes

yes

Foreign Function Interface

no

yes (replaces need for primitives; language also supports inline C/C++/Assembly)

yes (intrinsic COM and Distributed Object Services)

Macro System

no

no

no

Lexical Scopes

yes

yes

yes

Annotation System and Metadata Declarations

no

yes

yes

Security Validation

no

yes

yes

Graphics and GUI Services

yes

yes

yes

Integrated Source Level Debugging Facilities

yes

no (only available on the.NET platform version)

yes

Designed for Multi-paradigm support of component oriented programming

no

yes (intrinsic COM; .NET facilities available)

yes (intrinsic COM and .NET Facilities)




Copyright 1999-2010 by Smalltalk.org"!, All Rights Reserved.