Evolution of Software Languages 1 Evolution of Software Languages Theo D'Hondt Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences Vrije Universiteit Brussel Academic Year 2015-2016 Section 8: Simula⇾Smalltalk 6: Simula⇾Smalltalk
92
Embed
Section 8: Simula Smalltalk Evolution of Software …soft.vub.ac.be/~tjdhondt/ESL/Simula_to_Smalltalk_files...Evolution of Software Languages 3 Simula basics 6: Simula⇾Smalltalk
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Evolution of Software Languages 1
Evolution of
Software Languages
Theo D'Hondt
Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences
Vrije Universiteit Brussel Academic Year 2015-2016
Section 8: Simula⇾Smalltalk
6: Simula⇾Smalltalk
Evolution of Software Languages 2
Ole-Johan Dahl Kristen Nygaard
6: Simula⇾Smalltalk
http://www.jot.fm/issues/issue_2002_09/eulogy/
Simulation language Simula I ⇾ Simula 67 Extension of Algol 60 Call-by-value default Call-by-name still around Hoare’s Record Classes
Evolution of Software Languages 3
Simula basics
6: Simula⇾Smalltalk
The development of the SIMULA languages Kristen Nygaard, Ole-Johan Dahl
HISTORY OF PROGRAMMING LANGUAGES 439, 1981 ACM ISBN 0-12-745040-8
Class class C( ... ); begin ... end;
Prefix class A class B; begin ... end;
Nested classes class A; begin
class B; begin ... end; B class C; begin ... end; ...
end;
No multiple inheritance X, Y class Z( ... ); begin ... end;
Vehicle class Bike; begin procedure sound; begin OutText("Ding ding"); OutImage; end; end;
ref (Vehicle) array vehicles (1 : 2); Integer i; vehicles (1) :- new Car; vehicles (2) :- new Bike; for i := 1 step 1 until 2 do vehicles(i).sound end;
begin class Vehicle; virtual: procedure sound is procedure sound;; begin end;
Vehicle class Car ; begin procedure sound; begin OutText("Beep beep"); OutImage; end; end;
• Requires a workstation • 1Mpixels memory-mapped display • 1Mb memory • 32bits processor • pointing device with 2 buttons
• Uses a virtual machine with bytecodes • Uses a garbage collecting memory manager • Uses a uniform memory model (image) • Uses an integrated graphical kernel • Uses an object model for all language concepts • Single inhertance, ad-hoc poymorphism • Uses strong and dynamic typing of all values • Metaprogramming and computational reflection • A true IDE
Element of Smalltalk composed of private datastructures and a set of operations.
Request for an object to perform one of its operations.
Object that receives a message.
Set of messages identified by an object.
Specification of the set of objects with identical behaviour
Representative of a Class
Object
Message
Receiver
Interface
Class
Instance
Evolution of Software Languages 12
Terminology1
6: Simula⇾Smalltalk
Element of Smalltalk composed of private datastructures and a set of operations.
Request for an object to perform one of its operations.
Object that receives a message.
Set of messages identified by an object.
Specification of the set of objects with identical behaviour
Representative of a Class
Object
Message
Receiver
Interface
Class
InstanceEveryth
ing is an object
Evolution of Software Languages 13
Terminology2
6: Simula⇾Smalltalk
Instance variable
Method
Primitive method
System class
Name of a private datastructure of an object
Implementation of an operation of an object
Method directly executed by the Smalltalk virtual machine.
Class of the Smalltalk virtual image
Evolution of Software Languages 14
Literal objects
6: Simula⇾Smalltalk
Numerical Character String Symbol Aggregate
literal objects
#('January' 27 1985)
#((‘one' 1 $1) ('two' 2 $2) . . .
(‘zero' 0 $0))
Evolution of Software Languages 15
Variables
6: Simula⇾Smalltalk
Variable name
Private variables
Shared variables
Letters, digits
Lower case initial
Upper case initial
Evolution of Software Languages 16
Pseudo variables
6: Simula⇾Smalltalk
nil Undefined variable true, false Boolean values self, super Reference to receiver
Boolean object = object with interface all messages for logical operations
• Names that refer to specific objects
• Cannot be assigned a value with <-
• Some are constant
• Some have a value depending on the context
Evolution of Software Languages 17
Temporary variables
6: Simula⇾Smalltalk
• argument names and self only exist during the method activation
• moreover one can introduce local variables with the same characteristics
• these are being enumerated nominatively between message - pattern and method, preceded and followed by $| ; these are initialized to nil
Evolution of Software Languages 18
Assignment
6: Simula⇾Smalltalk
name1 <- name2 <- ... <- nameN <- expression
• binds structure as well as contents to a name
• name refers to an instance of the class determined by the expression
colour <- #('red' 'orange' 'green')
Evolution of Software Languages 19
Messages
6: Simula⇾Smalltalk
<receiver> = object that receives and implements the <selector> = identity of the message <arguments> = additional expressions that play a role in the method that implements the message
= interactions between objects
<receiver> <selector> [ <arguments> ]
Evolution of Software Languages 20
Message patterns
6: Simula⇾Smalltalk
one or two non alpha–numerical symbols ( last ≠ $–); there is exactly one argument
unary message
keyword message
numerator / denominator
operator message
alpha-numerical name and no arguments
discriminant sqrt
one or more alpha-numerical names each followed by $:; each keyword associated with an argument
letter from:'Donald' on:#(12 2 85)
Evolution of Software Languages 21
Message evaluation
6: Simula⇾Smalltalk
• The result of the evaluation of a method, consequence of the sending of a corresponding message, is an object
• Messages are bi-directional
sum <- 1 + 2 binds the integer object implementing 3 to sum
• The object returned by a method is not necessarily used
• Messages are 2nd class function calls
Evolution of Software Languages 22 6: Simula⇾Smalltalk
• the instance variables are automatically copied • the list of instance variables may be extended • the methods, if not "overridden" are being copied
• " overriding" happens by introducing a homonym at the subclass level
Evolution of Software Languages 48
Class names
6: Simula⇾Smalltalk
• class-names are unique
• instance variable names are unique within a class definition
• method-names ( message pattern) are unique within a class definition
• unique within a range of superclasses
Evolution of Software Languages 49
Superclasses
6: Simula⇾Smalltalk
• a superclass of a class K = a class which K is a subclass of
• normally :for each class K there is one superclass
for each class K there are 0 or more subclasses
• this defines an hierarchical structure at the root of which we find a unique class that has no superclass: Object
Evolution of Software Languages 50
Superclass chain
6: Simula⇾Smalltalk
• consider a class K
• the series of classes, beginning at Object and ending at K such that any 2 succesive classes are each other's superclass / subclass is the superclass chain of K
• if a message M with pattern P is sent to an instance I of K, the first method encountered with pattern P in the superclass chain of K is executed
Evolution of Software Languages 51
Method lookup
6: Simula⇾Smalltalk
(1) M - pattern in K ---> corresponding method is executed
(2) M - pattern not in K
---> (a) K = Object ---> abort
(b) K <> Object ---> substitute super (K) for K and ---> (1)
Evolution of Software Languages 52
ZZZ
6: Simula⇾Smalltalk
self • refers to M's receiver ( = instance I of K )
• M's method lookup starts in K
• if delegation ---> superclass this remains the case
super • = to self
• M's method lookup starts with the superclass of the class containing the method that contains the message
Evolution of Software Languages 53
Abstract superclasses
6: Simula⇾Smalltalk
• only serve to be transformed in subclasses
• should "never" be instantiated
Evolution of Software Languages 54
Subclass framework
6: Simula⇾Smalltalk
subclassResponsibility
• standard message in Object
• self subclassResponsability generates an errormessage, and is used as implementation of a message in an abstract subclass, which should be overridden in a subclass
shouldNotImplement
• standard message in Object
• self shouldNotImplement generates an errormessage and is used as implementation of a method that is impossible to implement.
Evolution of Software Languages 55
Metaclasses1
6: Simula⇾Smalltalk
• classes are objects ---> each class is instance of a class, called metaclass
• Object is superclass of each class
Evolution of Software Languages 56
Metaclasses2
6: Simula⇾Smalltalk
the class CLASS is:
• an abstract superclass of all metaclasses
• subclass of Object
a class and its (meta)class
• are defined together
• distinction is made between " class methods " and "instance methods "
• used for for class instantiation
Evolution of Software Languages 57
Metaclasses3
6: Simula⇾Smalltalk
metaclasses inherit from superclasses with a restriction: there is a parallellism in sub / superclasses between metaclasses and classes
IF :class c1 instance of metaclass m1
class c2 instance of metaclass m2
c1 subclass of c2 m1 subclass of m2
THEN :
Evolution of Software Languages 58
Object interface1
6: Simula⇾Smalltalk
functionality:
class ---> receiver's class
isKindOf: aClass ---> true if aClass
(super*) = receiver's class
isMemberOf: aClass ---> true if aClass = receiver's class
respondsTo: aSymbol ---> true if aSymbol element is of the interface of the receiver's class
Evolution of Software Languages 59
Object interface2
6: Simula⇾Smalltalk
== anobject
= anobject
~ = anobject
~~ = anobject
hash
---> true if receiver and anobject = ---> true if receiver and anobject refer to the same components
---> unique integer reference of the receiver
---> true if receiver and anobject are not ==
---> true if receiver and anobject are not =
comparison:
Evolution of Software Languages 60
Object interface3
6: Simula⇾Smalltalk
copy :
copy ---> instance with equal instance-variable content or shared variable
shallowCopy ---> instance with shared instance variables
deepCopy ---> instance with copy of the instance variables
Evolution of Software Languages 61
Object interface4
6: Simula⇾Smalltalk
access:
at : index
at : index put : anobject
basicAt : index
basicAt : index put : anobject
size
basicSize
Evolution of Software Languages 62
Object interface5
6: Simula⇾Smalltalk
error handling:
doesNotUnderstand: aMessagestates that the receiver does not understand "aMessage"
error : aString statement of error identified by "aString" to receiver
primitiveFailed statement that systemprimitive is abused by receiver
at: key "retrieve value corresponding to key" ^self at: key notFound: [ self error: 'key not found']
at: key notFound: block "retrieve value corresponding to key, with user error handling" | index | index := self indexAtKey: key. (index = 0) ifTrue: [ block value ] ifFalse: [ ^values at: index ]
at: key put: value "insert new key / value pair" self at: key put: value duplicate: [ self error: 'duplicate key' ]
Evolution of Software Languages 65
Dictionary framework3
6: Simula⇾Smalltalk
at: key put: value duplicate: block "insert new key / value pair with user error handling" | index | index <- self newIndexAtKey: key. (index = 0) ifTrue: [ block value ] ifFalse: [ values at: index put: value ]
at: key replace: value "replace value in existing pair" self at: key replace: value notFound: [self error: 'key not found' ]
at: key replace: value notFound: block "replace value in existing pair with user error handling" | index | index := self indexAtKey: key. (index = 0) ifTrue: [ block value ] ifFalse: [ values at: index put: value ]
Evolution of Software Languages 66
Dictionary framework4
6: Simula⇾Smalltalk
newIndexAtKey: key "locate index for new key in names" (( self indexAtKey: key) = 0) ifTrue: [ self extend . names at: names size put: key. ^ names size ] ifFalse: [ ^ 0 ]
extend "extend implementation by one pair" | oldNames oldValues newSize | oldNames := names. oldValues := values. newSize := names size + 1. names := Array new: newSize. values := Array new: newSize. (1 to: oldNames size) do: [ :index | names at: index put: ( oldNames at: index ). values at: index put: ( oldValues at: index ) ]
check: aTime "retrieve current flow" | time | top = 0 ifTrue: [ self error: 'Profile not initialized' ]. time := aTime rem: MaxTime. 1 to: top do: [ :index | (times at: index) >= time ifTrue: [ ^ flows at: index ] ]. ^ flows at: 1
configuration
register: aTime with: aFlow "set times and flows" top = MaxTable ifTrue: [ self error: 'Profile overflow' ]. top := top + 1. times at: top put: aTime. flows at: top put: aFlow
private
initProfile "initialize a new Profile" MaxTable isNil ifTrue: [ MaxTable := 10. MaxTime := 100 ]. top := 0. times := Array new: MaxTable. flows := Array new: MaxTable
class methods
instance creation
new "instantiate a new Profile " ^ super new initProfile
10 20
1
2
3
4
30 40 50 60 70 80 90
Evolution of Software Languages 89
Smalltalk goodies
6: Simula⇾Smalltalk
• Memory management with handles (become:)
• Garbage collection
• Integrated graphics (bitblt)
• Metaprogramming
• Processes
• Model view controller
• Collections
• ...
Evolution of Software Languages
• Memory management with handles (become:)
• Garbage collection
• Integrated graphics (bitblt)
• Metaprogramming
• Processes
• Model view controller
• Collections
• ...
90
Smalltalk goodies
6: Simula⇾Smalltalk
• No vararg (perform:)
• Closures ≠ methods
• Single image
• ...
BUT...
Evolution of Software Languages 91
Conclusion
6: Simula⇾Smalltalk
• Smalltalk is major milestone: less powerful than Lisp but much more accessible