FACTOID # 49: Kazakhstan is the world's largest landlocked country.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Smalltalk programming language

Smalltalk is a dynamically typed object oriented programming language designed at Xerox PARC by Alan Kay, Dan Ingalls, Ted Kaehler, Adele Goldberg, and others during the 1970s. The language was generally released as Smalltalk-80 and has been widely used since. Smalltalk is in continuing active development, and has gathered a loyal community of users around it.


Smalltalk has been a great influence on the development of many other computer languages, including: Objective-C, Actor, Java and Ruby (the latter one to such an extent that many Smalltalkers consider Ruby to be Smalltalk with a different syntax). Many software development ideas of the 1980s (Model-View-Controller, Class-Responsibility-Collaboration card) and 1990s came from the Smalltalk community, such as design patterns (as applied to software), Extreme Programming and refactoring. Among Smalltalkers is Ward Cunningham, the inventor of the WikiWiki concept.

Contents

Smalltalk's big ideas

Smalltalk's big ideas include:

  • "Everything is an object." Strings, integers, booleans, class definitions, blocks of code, stack frames, memory are all represented as objects. Execution consists of sending messages between objects. Any message can be sent to any object; the receiver object determines whether this message is appropriate and what to do to process it.
  • Everything is available for modification. If you want to change the IDE, you can do it-- in a running system, without stopping to recompile and restart. If you want a new control construct in the language, you can add it. In some implementations, you can change even the syntax of the language, or the way the garbage collection works.
  • Types are dynamic -- this means that you don't have to define types in the code, which makes the language much more concise. (As explained above, it is the receiver object rather than the compiler that decides whether an operation is appropriate).
  • Model-view-controller (MVC) pattern for structuring user interfaces.
  • Dynamic translation: modern commercial virtual machines compile bytecodes to the native machine code for fast execution, a technique pioneered by Smalltalk-80 from ParcPlace Systems in mid-1980s. This idea was adopted by Java some ten years later and named Just-in-time compilation.

Smalltalk also made use of other advanced ideas:

  • Garbage collection is built in and invisible to the developer.
  • Smalltalk programs are usually compiled to bytecodes and run by a virtual machine (VM), which allows them to be executable on any hardware platform for which a VM is available.

One surprising feature of Smalltalk is that the traditional progamming constructs: if-then-else, for, while, etc. are not built into the language. All of these things are implemented using objects. For example, decisions are made by sending an ifTrue: message to a Boolean object, and passing a fragment of code to execute if the Boolean is True. There are only three built-in executable constructs:

  • sending a message to an object;
  • assigning an object to a variable;
  • returning an object from a method;

and a few syntactic constructs for declaring literal objects and temporary variables.


The following code example for finding the vowels in a string illustrates Smalltalk's style. ( | characters declare variables, : declares parameters, and think of [ and ] as { and } curly braces for the moment):

 | aString vowels | aString := 'This is a string'. vowels := aString select: [:aCharacter | aCharacter isVowel].  

In the last line, the string is sent a select: message with the code block following as an argument. Here's the code in the superclass Collection that does the work:

 | newCollection | newCollection := self species new. self do: [:each | (aBlock value: each) ifTrue: [newCollection add: each]]. ^newCollection  

It responds to the message by iterating through its members (this is the do: method) evaluating aBlock code once for each character; aBlock (aCharacter isVowel) when evaluated creates a boolean, which is then sent ifTrue:. If the boolean is true, the character is added to a string to be returned. Because select is defined in the abstract class Collection, we can also use it like this:

 | rectangles aPoint| rectangles := OrderedCollection with: (Rectangle left: 0 right: 10 top: 100 bottom: 200) with: (Rectangle left: 10 right: 10 top: 110 bottom: 210). aPoint := Point x: 20 y: 20. collisions := rectangles select: [:aRect | aRect containsPoint: aPoint].  

History

Smalltalk was invented by a group of researchers led by Alan Kay at XEROX Palo Alto Research Center. The first implementation, known as Smalltalk-71, was created in a few mornings on a bet that a programming language based on the idea of message passing inspired by Simula could be implemented in "a page of code". A later version actually used for research work is now known as Smalltalk-72. Its syntax and execution model were very different from modern Smalltalk, so much so that it could be considered a different language.


After significant revisions which froze some aspects of executional semantics to gain performance, the version known as Smalltalk-76 was created. This version added inheritance, featured syntax much closer to Smalltalk-80, and had a development environment featuring most of the tools now familiar to Smalltalkers.


Smalltalk-80 added metaclasses, something which helps keep the "everything is an object" statement true by associating properties and behavior with individual classes (for example, to support different ways of creating instances). Smalltalk-80 was the first version made available outside of PARC, first as Smalltalk-80 Version 1, given to a small number of companies and universities for "peer review". Later (in 1983) a general availability implementation, known as Smalltalk-80 Version 2, was released as an image (platform-independent file with object definitions) and a virtual machine specification.


Two of the currently popular Smalltalk implementations are descendants of those original Smalltalk-80 images. Squeak (http://www.squeak.org/) is an open source implementation derived from Smalltalk-80 Version 1 by way of Apple Smalltalk. VisualWorks is derived from Smalltalk-80 version 2 by way of Smalltalk-80 2.5 and ObjectWorks (both products of ParcPlace Systems, XEROX PARC spin-off company formed to bring Smalltalk to the market). As an interesting link between generations, here (http://wiki.cs.uiuc.edu/VisualWorks/Smalltalk-80+in+a+box) is a screenshot of Smalltalk-80 version 2 image running on Hobbes, a Smalltalk-80 VM implemented in VisualWorks.


Today, Smalltalk remains a niche language that has largely been pushed out by Java. IBM has indicated that they will stop supporting the language in the near future. However, there are smaller companies continuing selling Smalltalk environments, and with Squeak there is a relatively active community of developers. There is also a GNU version. More recently, Ruby has implemented many of Smalltalk's ideas, providing a more traditional syntax, an extensive standard library, and borrowing concepts from other languages such as Perl and Python.


Hello World

Trivial example

 Transcript show: 'Hello, world!' 

This example highlights two aspects of Smalltalk.


First, it is a "message send." Smalltalk does most of its computation by sending messages to objects. In this case, the message is "show: 'Hello, world!'", and the message gets sent to "Transcript". Transcript's "show:" method will be invoked to handle this message, which will look at its argument (the string 'Hello, world!') and display that argument on the transcript. (Note that if you try this example, you need to have a Transcript window open in order to see the results.)


Second, it illustrates the basic syntax of message-sending in Smalltalk: RECEIVER SPACE MESSAGE. There is no period after the receiver, unlike in C++'s popular OO syntax, and there are no parentheses around the arguments included in the message.


Object-oriented example

Class definition

 Object subclass: #MessagePublisher instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Smalltalk Examples' 

This is a simple stock definition with the class name and category filled in. Often, the environment will write most of it for you.


Method definition

 publish Transcript show: 'Hello, world!' 

This defines a method called "publish". The body of the method is the same code as shown in the trivial example.


Invocation

 MessagePublisher new publish 

This creates an instance of MessagePublisher ("MessagePublisher new"), then sends the "publish" message to it, that is, it invokes the "publish" method.


Implementations

External links

  • "Smalltalk.org" (http://www.smalltalk.org) advocacy site.
  • "Why Smalltalk?" (http://www.whysmalltalk.com) a community of Smalltalk developers.
  • GoodStart "Smalltalk" (http://www.goodstart.com) advocacy site.
  • The Early History of Smalltalk (http://gagne.homedns.org/%7etgagne/contrib/EarlyHistoryST.html) by Alan C. Kay
  • Free Smalltalk Books online (http://www.iam.unibe.ch/~ducasse/FreeBooks.html)
  • Smalltalk information visualization tool (http://www.softcentral.com/informationspace/)
Major programming languages (more)

Ada | ALGOL | APL | AWK | BASIC | C | C++ | C# | COBOL | Delphi | Eiffel | Fortran | Haskell | IDL | Java | JavaScript | Lisp | LOGO | ML | Objective-C | Pascal | Perl | PHP | PL/I | Prolog | Python | Ruby | SAS | Scheme | sh | Simula | Smalltalk | SQL | Visual Basic


  Results from FactBites:
 
The Smalltalk programming language (2026 words)
Smalltalk is still a viable language, however, with several commercial implementations, and continues to be used in significant applications.
Smalltalk development environments have always focused on making the programmer as productive as possible by providing a completely integrated set of editing, code management, and debugging tools; they are still the premier examples.
One of the reasons for the simplicity of the Smalltalk language is that control structures, such as conditional execution, are defined as messages to objects.
Encyclopedia4U - Smalltalk programming language - Encyclopedia Article (586 words)
Smalltalk is a dynamically typed object oriented programming language designed at Xerox PARC by Alan Kay, Dan Ingalls, Ted Kaehler Adele Goldberg, and others during the 1970s.
Among Smalltalkers is Ward Cunningham, the inventor of the WikiWiki concept.
Smalltalk programs are usually compiled to bytecodes, run by a virtual machine.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.