3A-1 1 Introduction to Smalltalk History of Smalltalk The philosophy of Smalltalk: “...we have a...

12
3A-1 1 Introduction to Smalltalk Introduction to Smalltalk History of Smalltalk The philosophy of Smalltalk: ...we have a universe of well-behaved objects that courteously ask each other to carry out their various desires.” Dan Ingalls, Byte ‘81. Basic notions: Class and instance Message and method Some Smalltalk programs The class library Objectives: To mentally prepare for the next lecture... Read Smalltalk. To be able to write Smalltalk code.

Transcript of 3A-1 1 Introduction to Smalltalk History of Smalltalk The philosophy of Smalltalk: “...we have a...

3A-1

1

Introduction to SmalltalkIntroduction to Smalltalk• History of Smalltalk

• The philosophy of Smalltalk: “...we have a universe of well-behaved

objects that courteously ask each other to carry out their various desires.”

Dan Ingalls, Byte ‘81.

• Basic notions: Class and instance

Message and method

• Some Smalltalk programs

• The class library

• Objectives: To mentally prepare for the next lecture...

Read Smalltalk.

To be able to write Smalltalk code.

3A-2

2

Historical BackgroundHistorical Background

Simula 67

Pascal

C

CLOS

New Flavors

Flavors

Common LoopsObject Pascal

Quick Pascal Turbo Pascal C++

C with classes

C86Ada

Little Smalltalk

1990

1980

1970

1960 Algol 60Lisp

Smalltalk-72

Smalltalk-74

Smalltalk-76

Smalltalk-80

Smalltalk-78

Common LispLOOPS

Clascal

ANSI C++ Squeak

3A-3

3

Smalltalk HistorySmalltalk History

• Developed at the Xerox Palo Alto Research Center (Xerox PARC): Smalltalk-72

Smalltalk-76

Smalltalk-80

• Originally intended for children. Ideas from: Simula-67

Lisp

Logo

• Xerox pioneer ideas fumbled by the company: Smalltalk

GUI

PostScript

3A-4

4

Smalltalk VersionsSmalltalk Versions

• Smalltalk-80: product of ParcPlace. UNIX, Mac, MS-DOS. ObjectWorks

VisualWorks

• Smalltalk/V: product of Digitalk. MS-DOS, Windows, OS/2, Mac.

• Gnu Smalltalk: X based GUI. Compatible with Smalltalk-80. Still under development. UNIX. Free.

• VisualAge: product of IBM. OS/2, Windows.

• Squeak Started at Apple, continued at Walt Disney Imagineering

Derived directly from Smalltalk-80

Free, open source

Goals:

Portable

Written in Smalltalk

3A-5

5

Squeak in Our CourseSqueak in Our Course

• Squeak installed on: SSDL Lab

Can be downloaded from: http://www.squeak.org/

• Versions: Windows

Linux

• Read all about it in the Assignment

Yes, it is legal to download it and work at home!

No, we will not give technical support for those who wish to work at home!

3A-6

Why Squeak?Why Squeak?

Pure object-oriented language and environment “Everything is an object”

Language and environment Class browser, debugger, inspector, … Mature class library and tools

Virtual machine Objects exist in a persistent image [+ changes] Portable: Compile once, run everywhere

Open-source, implemented in Smalltalk Based on original Smalltalk-80 code

6

3A-7

Squeak by ExampleSqueak by Example www.SqueakByExample.org

Free PDF download

7

3A-8

8

A QuestionA Question• What is the result of the Smalltalk expression:

1 + 2 * 3

• Answer: 9 ( Why?!? )

• In Smalltalk, 1 is an object. We sent it a message with selector + and argument 2. The response to this message is the object 3. Then, 3 receives the message * with argument 3 and responds 9.

• The objects 1, 2 and 3 know how to respond to messages like + and *, since they are all integer numbers.

• In Smalltalk, we say that 1, 2 and 3 are instances of the class SmallInteger.

Each object is an instance of a class.

3A-9

9

In Smalltalk, everything is an In Smalltalk, everything is an objectobject

• There is no way to create an entity that is not an object.

• Every object contains a small amount of memory == instance variables. Only the object can access its memory.

An object’s memory can contain only other objects.

• Computation: send messages to objects.

• Objects have methods: what to do when messages are received.

• Each object is a member of exactly one class.

• Classes are organized in an inheritance tree. Multiple inheritance only in very specialised versions.

3A-10

10

Class LibraryClass Library

• Smalltalk core is: simple

minimal syntax

• The language lives and dies by its class library.

• Different in every implementation and in every version.

• Almost always includes: Boolean

Numbers: integers, floating, ...

Strings

Collections: sets, bags, arrays, lists, search tables ...

(User interface)

• Can be subclassed by user.

3A-11

11

BonBon• Business Object Notation

• AKA: Better Object Notation

• Inventors: Jean-Marc Nerson and Kim Walden (1995)

• Legend (partial)

AbstractClass*

AbstractClass*

ClassClassObject

Inheritance

3A-12

12

Squeak Class LibrarySqueak Class Library

ArrayedCollection*ArrayedCollection*

Collection*Collection*

Boolean* Boolean*

FalseFalse

false

TrueTrue

true

CharacterCharacter

Object*Object*

Magnitude*Magnitude*

Number*Number*

IntegerInteger FloatFloat

SetSet

DictionaryDictionary

SequenceableCollection*

SequenceableCollection*

ArrayArrayStringString

This is only a partial view

ProtoObject*ProtoObject*