smalltalk - vascogrilo/LDE GitHub Wiki
Squeak and SmallTalk
SmallTalk
http://en.wikipedia.org/wiki/Smalltalk
Smalltalk is a pure object-oriented language, simple and uniform. Smalltalk influenced most of the modern object-oriented languages, although most of the time they missed Smalltalk's elegance and simplicity.
The syntax of Smalltalk fits into one postcard and the object model is simple:
- Everything is an object.
- Objects communicate via message passing.
- Classes describe in terms of state (instance variables) and behavior (methods) the objects they generate.
- When an object receives a message, the corresponding method is looked up in the class (and superclass) of the receiver.
- Methods are public.
- Instance variables are private.
- Classes inherit via single inheritance.
Here is an example of Smalltalk (using Squeak's Morphic GUI classes) that creates an ellipse, changes its color to blue and shows it on the screen:
EllipseMorph new color: Color blue; openInWorld.
Two of the currently popular Smalltalk implementation variants are descendants of those original Smalltalk-80 images. Squeak 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, a Xerox PARC spin-off company formed to bring Smalltalk to the market). As an interesting link between generations, in 2002 Vassili Bykov implemented Hobbes, a virtual machine running Smalltalk-80 inside VisualWorks.
Reflection
Smalltalk-80 is a totally reflective system, implemented in Smalltalk-80 itself. Smalltalk-80 provides both structural and computational reflection.
Smalltalk is a structurally reflective system whose structure is defined by Smalltalk-80 objects. The classes and methods that define the system are themselves objects and fully part of the system that they help define.
The Smalltalk compiler compiles textual source code into method objects, typically instances of CompiledMethod. These get added to classes by storing them in a class's method dictionary. The part of the class hierarchy that defines classes can add new classes to the system. The system is extended by running Smalltalk-80 code that creates or defines classes and methods. In this way a Smalltalk-80 system is a "living" system, carrying around the ability to extend itself at run time.
Since the classes are themselves objects, they can be asked questions such as:
- "what methods do you implement?"
- "what fields/slots/instance variables do you define?"
So objects can easily be inspected, copied, (de)serialized and so on with generic code that applies to any object in the system.
Smalltalk-80 also provides computational reflection, the ability to observe the computational state of the system. In languages derived from the original Smalltalk-80 the current activation of a method is accessible as an object named via a pseudo-variable (one of the six reserved words), thisContext. By sending messages to thisContext a method activation can ask questions like "who sent this message to me". These facilities make it possible to implement co-routines or Prolog-like back-tracking without modifying the virtual machine.
The exception system is implemented using this facility. One of the more interesting uses of this is in the Seaside web framework which relieves the programmer of dealing with the complexity of a Web Browser's back button by storing continuations for each edited page and switching between them as the user navigates a web site. Programming the web server using Seaside can then be done using a more conventional programming style.
When an object is sent a message that it does not implement, the virtual machine sends the object the doesNotUnderstand: message with a reification of the message as an argument. The message (another object, an instance of Message) contains the selector of the message and an Array of its arguments. In an interactive Smalltalk system the default implementation of doesNotUnderstand: is one that opens an error window (a Notifier) reporting the error to the user. Through this and the reflective facilities the user can examine the context in which the error occurred, redefine the offending code, and continue, all within the system, using Smalltalk-80's reflective facilities.
Another important use of doesNotUnderstand: is intercession. One can create a class that does not define any methods other than doesNotUnderstand: and does not inherit from any other class. The instances of this class effectively understand no messages. So every time a message is sent to these instances they actually get sent doesNotUnderstand:, hence they intercede in the message sending process. Such objects are called proxies. By implementing doesNotUnderstand: appropriately, one can create distributed systems where proxies forward messages across a network to other Smalltalk systems (a facility common in systems like CORBA, COM+ and RMI but first pioneered in Smalltalk-80 in the 1980s), and persistent systems where changes in state are written to a database and the like. An example of this latter is Logic Arts' VOSS (Virtual Object Storage System) available for VA Smalltalk under dual open source and commercial licensing.
Squeak
http://en.wikipedia.org/wiki/Squeak
http://www.squeak.org/Documentation/
http://www.squeak.org/Features/
http://wiki.squeak.org/squeak
http://squeakbyexample.org/ , Ler PDF http://paginas.fe.up.pt/~ei10125/squeakbyexample.pdf
The Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.
It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers. Its development was continued by the same group at Walt Disney Imagineering, where it was intended for use in internal Disney projects.
Squeak is a modern open-source development environment for the classic Smalltalk-80 programming language. Despite being the first purely object-oriented language and environment, Smalltalk is in many ways still far ahead of its successors in promoting a vision of an environment where everything is an object, and anything can change at run-time.
Features
The list of features in Squeak is astonishing. What would, in other environments, be third party extensions downloadable elsewhere comes fully integrated in the standard Squeak release.
Smalltalk, the language, is:
- Dynamically Typed
- Strongly Typed
- Garbage Collected
- Interpreted
- Purely Object-Oriented
- Open Source
- Reflective
- Extensible
- Cross-platform
- Cross-OS
- Cross-hardware
Some features of Squeak:
- Squeak's virtual machine is developed using Squeak itself. It is possible to execute and debug Squeak inside Squeak!
- Squeak can be used for Web Application Development.
- Squeak has superb multi-media potential!
- Squeak is internationalised! It supports Unicode and Localization for multi-lingual applications.
- Squeak is a persistent environment - when you save your image, every thing right down to the position of windows and text is saved.
- Squeak itself is an IDE. You can code, run and debug in the same environment.
- Squeak uses incremental compiling - once you've saved your code, it's ready to run!