Squeak

From Bauman National Library
This page was last modified on 8 June 2016, at 09:48.
Squeak
100px
Original 1996 logo by Tim Rowledge[1]
225px
Screenshot of a Squeak application running under X11.
Paradigm object-oriented
Designed by Alan Kay, Dan Ingalls, Adele Goldberg
Developers Alan Kay, Dan Ingalls, Ted Kaehler, Scott Wallace, John Maloney, Andreas Raab, Mike Rueger
Stable release 5.0 / August 12, 2015; 7 years ago (2015-08-12)[2]
Typing discipline Dynamic
Platform Cross-platform
OS Cross-platform: Unix-like, OS X, iOS, Windows, more
License MIT, Apache
Website www.squeak.org
Major implementations
Squeak, Croquet
Dialects
Pharo, Croquet
Influenced by
Smalltalk, Lisp, Logo; Sketchpad, Simula; Self
Influenced
Etoys, Tweak, Croquet, Scratch

Squeak is a tightly integrated software development environment for live software construction using the object-oriented programming language Smalltalk. It runs on many computers and operating systems. Squeak is free and open source. It features the Morphic framework, which promotes low effort graphical, interactive application development and maintenance.

History

"The big idea is 'messaging' — that is what the kernel of Smalltalk/Squeak is all about" - Alan Kay

Squeak may be called a dialect of Smalltalk language, and it's currently one of the two popular Smalltalk implementations (the other is VisualWorks). Squeak is derived from Smalltalk-80 Version 1 by way of Apple Smalltalk. According to Alan Kay, one of the project contributors and the designer of Smalltalk itself, the name "Squeak" was originally a name of a folder on his Mac, wich he used to store the development files of this new dialect. The core team behind Squeak includes Dan Ingalls (main design paper author), Alan Kay, Ted Kaehler, John Maloney, and Scott Wallace. Squeak began with the needs of a research group at Apple, who wanted a system as expressive and immediate as Smalltalk to pursue various application goals, such as prototypical educational software and user interface experiments. Developers share the goal of improving original Smalltalk-80 system to serve a wide range of research and academic needs, higher performing interpreter, support for block closures, exception handling, finalization efforts, new graphics model.

Squeak 4.0 may be downloaded at no cost, including source code, as a prebuilt virtual machine image licensed under the MIT License, with the exception of some of the original Apple code, which is governed by the Apache License. For each contribution made under the Squeak License since 1996, a relicensing statement was obtained authorizing distribution under the MIT license, and finally in March 2010, the end result was released as Squeak 4.0, now under combined MIT and Apache licenses.

Squeak is still being developed, latest release 5.0 is dated 12 of August 2015.

Language

Paradigm

Smalltalk is a purely object-oriented reflective language which cleanly supports the notion of classes, methods, messages and inheritance. All Smalltalk code is composed of chains of messages sent to objects. Even the programming environment itself is designed within this metaphor. All of this functionality is always accessible to browsing and change, a fact which makes Smalltalk an extremely flexible system.

Early version's (before 3.8) system's basic functionality is rooted in the so called Model, View, Controller metaphor, where the phrase model refers to those pieces of code which describe all logically related structural and behavioural aspects of a specific application; a "program" in a conventional sense. A view is a screen representation for a model, which will typically reside in a window and reflect some of the model's aspects in textual or graphical form. Those two concepts are orthogonal in the sense that more than a single view of a model may be active at any given point in time. Controller entities, finally, offer the means for user interaction.

Modern Squeak environment is based on Morphic interface framework.

Type system

As direct Smalltalk descendant, Squeak inherits it's type discipline - dynamic typing. "Everything is an object" - Smalltalk is the language that started the Object Oriented Programming revolution. The Smalltalk "object" is very similar to the Java or C++ object. In particular, each object is stored in memory and has several fields, which can point to other objects or contain primitive data values. Each object belongs to exactly one class. Classes are related in a tree-shaped hierarchy, so each class has exactly one superclass, so Smalltalk has single-inheritance. In Smalltalk, the primitive values (instances of SmallIntegers) are really first-class objects. There is a single class called SmallInteger, and when the programmer adds a new method to it, it can be used in exactly the same way as any other method. In Smalltalk, we can send messages to SmallIntegers.

Languages like Java and C++ make a distinction between "types" and "classes". In Smalltalk there are no constraints on what can be assigned to a variable. Any variable may point to any class of object. It is the programmer's responsibility to make sure that a variable's value is of the correct class at run-time.

Syntax

Squeak is backwards-compatible with Smalltalk-80, with a few notable extentions. Comments in Squeak are enclosed in quotes(").

Variables

Variables must be declared before use, shared variabless must begin with uppercase, local ones with lowercase.

Assignment

x _ 4.                                                      "assignment (Squeak) <-"
x := 5.                                                     "assignment"
x := y := z := 6.                                           "compound assignment"
x := (y := 6) + 1.
x := Object new.                                            "bind to allocated instance of a class"
x := 123 class.                                             "discover the object class"
x := Integer superclass.                                    "discover the superclass of a class"
x := Object allInstances.                                   "get an array of all instances of a class"
x := Integer allSuperclasses.                               "get all superclasses of a class"
x := 1.2 hash.                                              "hash value for object"
y := x copy.                                                "copy object"
y := x shallowCopy.                                         "copy object (not overridden)"
y := x deepCopy.                                            "copy object and instance vars"
y := x veryDeepCopy.                                        "complete tree copy using a dictionary"

Constants

b := true.                                                  "true constant"
b := false.                                                 "false constant"
x := nil.                                                   "nil object constant"
x := 1.                                                     "integer constants"
x := 3.14.                                                  "float constants"
x := 2e-2.                                                  "fractional constants"
x := 16r0F.                                                 "hex constant".
x := -1.                                                    "negative constants"
x := 'Hello'.                                               "string constant"
x := 'I''m here'.                                           "single quote escape"
x := $A.                                                    "character constant"
x := $ .                                                    "character constant (space)"
x := #aSymbol.                                              "symbol constants"
x := #(3 2 1).                                              "array constants"
x := #('abc' 2 $a).                                         "mixing of types allowed"

Blocks

Blocks are objects and may be assigned to a variable, it's value is last expression evaluated unless explicit return. Squeak does not currently support localvars in blocks, max of three arguments is allowed.

x := [ y := 1. z := 2. ]. x value.                          "simple block usage"
x := [ :argOne :argTwo |   argOne, ' and ' , argTwo.].      "set up block with argument passing"
Transcript show: (x value: 'First' value: 'Second'); cr.    "use block with argument passing"
"x := [ | z | z := 1.].                                      localvars not available in squeak blocks"

Message passing and methods

Methods in Smalltalk are similar to methods in Java and C++, where they are called "member functions". Methods may take arguments and may return a result. A method is similar to a function; in this analogy, sending a message is similar to calling a function. An expression which invokes a method is called a "message sending expression". In the Smalltalk programming model, all binding is dynamic.

Unary message:

receiver := 5.
message := 'factorial' asSymbol.
result := receiver perform: message.

Binary message:

receiver := 1.
message := '+' asSymbol.
argument := 2.
result := receiver perform: message withArguments: (Array with: argument).

Metaclasses and Reflection

Each class is represented using a single object, called "class-representing objects". Such objects can be queried and modified. Since these class-representing objects are normal objects, just like any others, they must be instances of classes. Therefore each class is an instance of a metaclass.

x := String name.                                           "class name"
x := String category.                                       "organization category"
x := String comment.                                        "class comment"
x := String kindOfSubclass.                                 "subclass type - subclass: variableSubclass, etc"
x := String definition.                                     "class definition"
x := String instVarNames.                                   "immediate instance variable names"
x := String allInstVarNames.                                "accumulated instance variable names"
x := String classVarNames.                                  "immediate class variable names"
x := String allClassVarNames.                               "accumulated class variable names"
x := String sharedPools.                                    "immediate dictionaries used as shared pools"
x := String allSharedPools.                                 "accumulated dictionaries used as shared pools"
x := String selectors.                                      "message selectors for class"
x := String sourceCodeAt: #size.                            "source code for specified method"
x := String allInstances.                                   "collection of all instances of class"
x := String superclass.                                     "immediate superclass"
x := String allSuperclasses.                                "accumulated superclasses"
x := String withAllSuperclasses.                            "receiver class and accumulated superclasses"
x := String subclasses.                                     "immediate subclasses"
x := String allSubclasses.                                  "accumulated subclasses"
x := String withAllSubclasses.                              "receiver class and accumulated subclasses"
b := String instSize.                                       "number of named instance variables"
b := String isFixed.                                        "true if no indexed instance variables"
b := String isVariable.                                     "true if has indexed instance variables"
b := String isPointers.                                     "true if index instance vars contain objects"
b := String isBits.                                         "true if index instance vars contain bytes/words"
b := String isBytes.                                        "true if index instance vars contain bytes"
b := String isWords.                                        true if index instance vars contain words"
Object withAllSubclasses size.                              "get total number of class entries"

Runtime

The current Squeak interpreter combines a classic ST-80 interpreter with a simple yet efficient 32-bit direct-pointer object memory, and incremental garbage collector. It also includes a BitBlt graphics system that supports 1-, 2-, 4-, and 8-bit indexed colors, as well as 16- and 32-bit rgb colors, plus a "warp drive" that supports fast rotations and other affine transformations, as well as simple anti-aliasing. Other notable, and equally portable, abilities of Squeak include 16-bit sound input and output, and support for sockets and internet access. Each Smalltalk/Squeak system follows exactly the same virtual machine specification. Both the objects and the virtual machine code are represented identically on all machines. The innovation of the "Squeak" implementation was to re-code the virtual machine entirely in Smalltalk itself.

The execution model of Smalltalk is quite different from traditional languages. With Smalltalk, the heap is an ongoing entity, persisting over days, months, or years. In Smalltalk, the heap is called the image. The heap and all the objects in it are kept in a disk file when the system is not being used. At the beginning of a Smalltalk session, the virtual machine will read the mage from disk into memory and then begin executing code it contains. When the heap is stored on disk during a snapshot, all pointers are preserved, the objects are not converted into text or transformed in any other way. In effect, the bytes of memory are just written directly out to disk, although pointer address re-mapping will occur when the image is started up at a later time in a different memory location. At any one time, there are many different threads (i.e., "lightweight processes") running in any Smalltalk image. All process-control-blocks and stack frames are first-class objects, so the full state of each of these threads will also be captured during a snapshot. Upon a restore, each of these threads will resume execution from the saved state without missing a beat.

A fundamental difference between Smalltalk and other languages is that the unit of compilation in Smalltalk is a single method. In Smalltalk, the programmer edits a method. After finishing, the programmer clicks a button and the method is re-compiled. The compilation is instantaneous, much faster than C++ or Java. Furthermore, there is no separate link or load phase.

Environment

Morphic interface

Morphic is a direct-manipulation User Interface (UI) construction kit based on display trees. It works with graphical objects called Morphs. It replaces the original Model View Controller graphics toolkit of Smalltalk-80. A Morph is the central abstraction of Morphic, and is simply a Squeak object that has a visual representation that can be picked up and moved.

In addition, a morph may:

  • perform actions in response to user inputs.
  • perform an action when another morph is dropped onto it, or when it is dropped onto another morph.
  • perform an action at regular intervals.
  • control the placement and size of its submorphs.

Any morph can have component morphs (called submorphs). A composite morph is treated as a single unit: moving, copying, or deleting a composite morph causes all its submorphs to be moved, copied, or deleted as well. By convention, all morphs are visible; morphic does not use invisible structural morphs for aggregation. This means that if a composite morph is disassembled, all its component morphs can be seen and manipulated.

Programming is performed in one or more Workspaces - windows with rich text editing functionality. Programmer can type in any Smalltalk code inside the workspace window and execute it or inspect it. This is normally done by typing in some code, highlighting it with the mouse, and then selecting "do it" or "print it" or "inspect it" from the pop-up menu.

External links

  • "Tim: Squeak Smalltalk". Retrieved 2016-02-28. 
  • "4.5 Release Notes".