S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms The C Programming Language.
Advertisements

CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Elementary Data Types Prof. Alamdeep Singh. Scalar Data Types Scalar data types represent a single object, i.e. only one value can be derived. In general,
S.Ducasse 1 Metaclasses in 7 Steps Classes are objects too... Classes are instances of other classes... One model applied twice.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
11. A bit of Smalltalk. © O. Nierstrasz P2 — A bit of Smalltalk 11.2 A bit of Smalltalk Overview  Some history  Smalltalk syntax & object model  The.
Principles of Object-Oriented Software Development The language Smalltalk.
Road Map Introduction to object oriented programming. Classes
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
7. Understanding Classes and Metaclasses. © Oscar Nierstrasz ST — Understanding Classes and Metaclasses 7.2 Roadmap  Metaclasses in 7 points  Indexed.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse8.1 Syntax and Messages The syntax of Smalltalk is simple and uniform, but it can look strange at first sight! Literals: numbers, strings,
Stéphane Ducasse 1 The Taste of Smalltalk.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Some Basic Points on Classes
S.Ducasse Stéphane Ducasse 1 A Taste of Smalltalk.
Stéphane Ducasse 1 Syntax and Messages.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
Stéphane Ducasse«ChapterNr».1 Advanced Classes Indexed Classes Classes as Objects Class Instance Variables and Methods Class Variables Pool Dictionaries.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
12. A bit of Smalltalk. © O. Nierstrasz P2 — A bit of Smalltalk 11.2 Roadmap  Some history  Smalltalk syntax & object model  The Smalltalk environment.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
Stéphane Ducasse4.1 A Taste of Smalltalk Two examples: –‘hello world’ –A Tomagoshi To give you an idea of: –the syntax –the elementary objects and classes.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
S.Ducasse Stéphane Ducasse 1 Classes and Metaclasses - an Analysis.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Smalltalk for Unix & W i n d o w s Dennis Smith Cherniak Software Development Corporation.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
Squeak and Botkit-Port Jeff Forbes Joel Miller. Introduction ● Squeak is a pure OO language ● Based off of SmallTalk-80 – Designed at Xerox PARC by Alan.
Stéphane Ducasse 1 Elements of Design - Inheritance/Compositio n.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Smalltalk in a.NET World How to write a Smalltalk compiler without writing a VM John Brant
Stéphane Ducasse 1 Singleton.
S.Ducasse 1 7. Understanding Metaclasses. S.Ducasse 2 Roadmap Metaclasses in 7 points Indexed Classes Class Instance Variables Class Variables Pool Dictionaries.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
S.Ducasse Stéphane Ducasse 1 Common Mistakes and Debugging in VW.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
Stéphane Ducasse 1 Some Advanced Points on Classes.
3C-1 Identifiers Variables Literal Objects  Numbers  Characters  Strings Control Structure  Blocks  Conditionals  Loops Messages Defining New Classes.
Stéphane Ducasse7.1 Let’s Play Objects Simulate a LAN physically Set up a context for –future chapters –Exercises Some forward references to intriguate.
S.Ducasse Marcus Denker 1 Working with Bytecodes: IRBuilder and InstructionStream.
Stéphane Ducasse 1 Some Points on Classes.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
Stéphane Ducasse 1 A Little Journey in the Smalltalk Syntax.
OOP Basics Classes & Methods (c) IDMS/SQL News
Stéphane Ducasse 1 Abstract Classes.
S.Ducasse Stéphane Ducasse 1 Some Advanced Points on Classes.
Administrative Issues Lecture 22 – Prolog (III), Fall 2007 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, HW3 (due at March 18 th ) Essay.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Let’s Play Objects.
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Smalltalk – a Pure (and first) OOPL
Chapter 2 Squeak: Object-oriented design with multimedia applications
CS 331 Principles of Programming Languages
Introduction to Smalltalk
Let’s Talk about… Smalltalk.
Introduction to Smalltalk
CSE 3302 Programming Languages
Smalltalk on a Dime.
Presentation transcript:

S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell

S.Ducasse License: CC-Attribution-ShareAlike

S.Ducasse 3 Goals Syntax in a Nutshell OO Model in a Nutshell

S.Ducasse 4 Smalltalk OO Model ***Everything*** is an object  Only message passing  Only late binding Instance variables are private to the object Methods are public Everything is a pointer Garbage collector Single inheritance between classes Only message passing between objects

S.Ducasse 5 Complete Syntax on a PostCard exampleWithNumber: x “A method that illustrates every part of Smalltalk method syntax except primitives. It has unary, binary, and key word messages, declares arguments and temporaries (but not block temporaries), accesses a global variable (but not and instance variable), uses literals (array, character, symbol, string, integer, float), uses the pseudo variable true false, nil, self, and super, and has sequence, assignment, return and cascade. It has both zero argument and one argument blocks. It doesn’t do anything useful, though” |y| true & false not & (nil isNil) ifFalse: [self halt]. y := self size + super size. #($a #a ‘a’ 1 1.0) do: [:each | Transcript show: (each class name); show: (each printString); show: ‘ ‘]. ^ x < y

S.Ducasse 6 Language Constructs ^return “ comments #symbol or array ‘string [ ]block or byte array.separator and not terminator (or namespace access in VW) ;cascade (sending several messages to the same instance) |local or block variable :=assignment $character :end of selector name e, rnumber exponent or radix !file element separator for VM primitive calls

S.Ducasse 7 Syntax comment:“a comment” character:$c $h $a $r $a $c $t $e $r $s $# string: ‘a nice string’ ‘lulu’ ‘l’’idiot’ symbol: #mac #+ array: #(1 2 3 (1 3) $a 4) byte array:#[1 2 3] integer: 1, 2r101 real: 1.5, 6.03e-34,4, 2.4e7 float: 1/33 boolean: true, false point: Note is not an element of the syntax, but just a message sent to a number. This is the same for /, bitShift, ifTrue:, do:...

S.Ducasse 8 Syntax in a Nutshell (II) assigment: var := aValue block: [:var ||tmp| expr...] temporary variable: |tmp| block variable: :var unary message: receiver selector binary message: receiver selector argument keyword based: receiver keyword1: arg1 keyword2: arg2... cascade: message ; selector... separator: message. message result: ^ parenthesis: (...)

S.Ducasse 9 Messages vs. a predefined Syntax In Java, C, C++, Ada constructs like >>, if, for, etc. are hardcoded into the language grammar In Smalltalk there are just messages defined on objects (>>) bitShift: is just a message sent to numbers – 10 bitShift: 2 (if) ifTrue: is just messages sent to a boolean – (1> x) ifTrue: (for) do:, to:do: are just messages to collections or numbers – #(a b c d) do: [:each | Transcript show: each ; cr] – 1 to: 10 do: [:i | Transcript show: each printString; cr] Minimal parsing Language is extensible

S.Ducasse 10 Class Definition: A message sent to a namespace Smalltalk defineClass: #NameOfClass superclass: #{NameOfSuperclass} indexedType: #none private: false instanceVariableNames: '' classInstanceVariableNames: '' imports: '' category: 'Browser-Commands' Class Definition in VW

S.Ducasse 11 NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'classVarName1' poolDictionaries: '' category: 'LAN' Class Definition in Squeak

S.Ducasse 12 Method Definition Normally defined in a browser or (by directly invoking the compiler) Methods are public Always return self Node>>accept: thePacket "If the packet is addressed to me, print it. Else just behave like a normal node" (thePacket isAddressedTo: self) ifTrue: [self print: thePacket] ifFalse: [super accept: thePacket]

S.Ducasse 13 Instance Creation: Messages Too! ‘1’, ‘abc’ Basic class creation messages are new, new:, basicNew, basicNew: Monster new Class specific message creation(messages sent to classes) Tomagoshi withHunger: 10

S.Ducasse 14 Messages and their Composition Three kinds of messages – Unary: Node new – Binary: 1 + 2, – Keywords: aTomagoshi eat: #cooky furiously: true – Message Priority (Msg) > unary > binary > keywords Same Level from left to right Example: extent: bottomRight s isNil ifTrue: [ self halt ]

S.Ducasse 15 Anonymous method Passed as method argument or stored Functions fct(x)= x*x+3, fct(2). fct :=[:x| x * x + 3]. fct value: 2 Integer>>factorial tmp:= 1. 2 to: self do: [:i| tmp := tmp * i] #(1 2 3) do: [:each | Transcript show: each printString ; cr] Blocks

S.Ducasse 16 Summary Objects and Messages Three kinds of messages unary binary keywords Block: a.k.a innerclass or closures or lambda Unary>Binary>Keywords

S.Ducasse 17 Goals Syntax in a Nutshell OO Model in a Nutshell

S.Ducasse 18 Instance and Class Only one model Uniformly applied Classes are objects too

S.Ducasse 19 Lookup…Class + Inheritance 1 2

S.Ducasse 20 Classes are objects too Instance creation is just a message send to a... Class Same method lookup than with any other objects a Class is the single instance of amanonymous class Point is the single instance of Point class

S.Ducasse 21 Class Parallel Inheritance

S.Ducasse 22 Lookup and Class Methods Workstation withName: ‘BigMac’ aWorkstation name

S.Ducasse 23 About the Buttons

S.Ducasse 24 Summary - Everything is an object - One single model - Single inheritance - Public methods - Private attribute - Classes are simply objects too - Class is instance of another class - One unique method lookup look in the class of the receiver