S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.

Slides:



Advertisements
Similar presentations
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Advertisements

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,
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.
Stéphane Ducasse«ChapterNr».1 Selected Design Patterns Design Patterns are recurrent solutions to design problems They are pros and cons We already saw:
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 
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.
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)
03G-1 Everything is an Object Examining builtin classes All these are classes in Little Smalltalk:  Object  Class  Method  Block  Boolean True False.
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.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
S.Ducasse Stéphane Ducasse 1 Classes and Metaclasses - an Analysis.
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.
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
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.
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.
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 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.
Java Primer 1: Types, Classes and Operators
Smalltalk – a Pure (and first) OOPL
Object-Oriented Programming
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 savoie.fr e/ e/ 1 Smalltalk in a Nutshell

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

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

S.Ducasse 4 Complete Syntax on a PostCard exampleWithNumber: x “Illustrates every part of Smalltalk method syntax. It has unary, binary, and key word messages, declares arguments and 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.” |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 5 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 6 Syntax in a Nutshell (I) 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 7 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 8 Messages instead of a predefined syntax In Java, C, C++, Ada constructs like >>, if, for, etc. are hardcoded into the 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 9 How to Define a Class (Sq)? Class Definition: A message sent to another class Object subclass: #Tomagoshi instanceVariableNames: ‘tummy hunger dayCount’ classVariableNames: '' poolDictionaries: '' category: ‘Monster Inc’ Instance variables are instance-based protected (not visible by clients)

S.Ducasse 10 Smalltalk defineClass: #Packet superclass: #{Object} indexedType: #none private: false instanceVariableNames: 'addressee originator contents' classInstanceVariableNames: '' imports: '' category: 'LAN' How to Define a Class (VW)?

S.Ducasse 11 How to Define a Method? Normally defined in a browser or (by directly invoking the compiler) Methods are public Always return self Tomagoshi>>digest "Digest slowly: every two cycles, remove one from the tummy” (dayCount isDivisibleBy: 2) ifTrue: [ tummy := tummy -1]

S.Ducasse 12 How to Define a Method? 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 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 Roadmap 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 Parallel Inheritance between classes

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 - Object based private attribute - Protected to subclasses - Classes are simply objects too - Class is instance of another class - One unique method lookup look in the class of the receiver