S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.

Slides:



Advertisements
Similar presentations
1 Object Orientation James Brucker. 2 Smalltalk  Ahead of its time: consistent design and rich library.  Dynamic (like Lisp): variables have no specified.
Advertisements

Programming Languages and Paradigms
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.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Principles of Object-Oriented Software Development The language Smalltalk.
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.
High-Level Programming Languages
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.
Stéphane Ducasse 1 Objects to the Roots: Learning from beauty.
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.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
CIS Computer Programming Logic
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.
Chapter 3: Data Types and Operators JavaScript - Introductory.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
S.Ducasse Stéphane Ducasse 1 Classes and Metaclasses - an Analysis.
Introduction to Computer Programming Using C Session 23 - Review.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
Chapter 12 Support for Object oriented Programming.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
Stéphane Ducasse 1 Elements of Design - Inheritance/Compositio n.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
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 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.
By Mr. Muhammad Pervez Akhtar
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.
Written by: Dr. JJ Shepherd
Stéphane Ducasse 1 Some Points on Classes.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
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.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
S.Ducasse Stéphane Ducasse 1 Some Advanced Points on Classes.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
S.Ducasse 1 Instance Initialization How to ensure that an instance is well initialized? Automatic initialize Lazy initialization Proposing the right interface.
CS314 – Section 5 Recitation 9
Let’s Play Objects.
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
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 Programming with BlueJ
Chapter 2 Squeak: Object-oriented design with multimedia applications
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 The Taste of Smalltalk

S.Ducasse License: CC-Attribution-ShareAlike

S.Ducasse 3 Goals Two examples: “hello world” a LAN simulator To give you an idea of: the syntax the elementary objects and classes the environment To provide the basis for all the lectures: all the code examples, constructs, design decisions,...

S.Ducasse 4 An Advice You do not have to know everything!!! “Try not to care - Beginning Smalltalk programmers often have trouble because they think they need to understand all the details of how a thing works before they can use it. This means it takes quite a while before they can master Transcript show: ‘Hello World’. One of the great leaps in OO is to be able to answer the question "How does this work?" with "I don’t care"“. Alan Knight. Smalltalk Guru We will show you how to learn and find your way

S.Ducasse 5 Some Conventions Return Values > 4 Node new -> aNode Method selector #add: Method scope conventions Instance Method defined in class Node: Node>>accept: aPacket Class Method defined in class Node (in the class of the the class Node) Node class>>withName: aSymbol aSomething is an instance of the class Something

S.Ducasse 6 Roadmap “hello world” Syntax a LAN simulator

S.Ducasse 7 Hello World Transcript show: ‘hello world’ At anytime we can dynamically ask the system to evaluate an expression. To evaluate an expression, select it and with the middle mouse button apply doIt. Transcript is a special object that is a kind of standard output. It refers to a TextCollector instance associated with the launcher.

S.Ducasse 8 Transcript show: ‘hello world’

S.Ducasse 9 Everything is an Object The workspace is an object. The window is an object: it is an instance of ApplicationWindow. The text editor is an object: it is an instance of ParagraphEditor. The scrollbars are objects too. ‘hello word’ is an object: it is aString instance of String. #show: is a Symbol that is also an object. The mouse is an object. The parser is an object: instance of Parser. The compiler is also an object: instance of Compiler. The process scheduler is also an object. The garbage collector is an object: instance of MemoryObject. Smalltalk is a consistent, uniform world written in itself. You can learn how it is implemented, you can extend it or even modify it. All the code is available and readable

S.Ducasse 10 Smalltalk Object 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 11 Roadmap Hello World First look at the syntax LAN Simulator

S.Ducasse 12 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 13 Yes ifTrue: is sent to a boolean Weather isRaining ifTrue: [self takeMyUmbrella] ifFalse: [self takeMySunglasses] ifTrue:ifFalse is sent to an object: a boolean!

S.Ducasse 14 Yes a collection is iterating on itself #( ) do: [:each | Transcript show: each abs printString ;cr ] > 1 > 2 > 4 > 86 Yes we ask the collection object to perform the loop on itself

S.Ducasse 15 DoIt, PrintIt, InspectIt and Accept Accept = Compile: Accept a method or a class definition DoIt: send a message to an object PrintIt: send a message to an object + print the result (#printOn:) InspectIt: send a message to an object + inspect the result (#inspect)

S.Ducasse 16 Objects send messages Transcript show: ‘hello world’ The above expression is a message the object Transcript is the receiver of the message the selector of the message is #show: one argument: a string ‘hello world’ Transcript is a global variable (starts with an uppercase letter) that refers to the Launcher’s report part.

S.Ducasse 17 Vocabulary Point Message passing or sending a message is equivalent to invoking a method in Java or C++ calling a procedure in procedural languages applying a function in functional languages of course the last two points must be considered under the light of polymorphism

S.Ducasse 18 Roadmap Hello World First look at the syntax LAN Simulator

S.Ducasse 19 A LAN Simulator A LAN contains nodes, workstations, printers, file servers. Packets are sent in a LAN and each node treats them differently.

S.Ducasse 20 Three Kinds of Objects Node and its subclasses represent the entities that are connected to form a LAN. Packet represents the information that flows between Nodes. NetworkManager manages how the nodes are connected

S.Ducasse 21 LAN Design

S.Ducasse 22 Interactions Between Nodes

S.Ducasse 23 Node and Packet Creation |macNode pcNode node1 printerNode node2 node3 packet| macNode := Workstation withName: #mac. pcNode := Workstation withName: #pc. node1 := Node withName: #node1. node2 := Node withName: #node2. node3 := Node withName: #node2. printerNode := Printer withName: #lpr. macNode nextNode: node1. node1 nextNode: pcNode. pcNode nextNode: node2. node3 nextNode: printerNode. lpr nextNode: macNode. packet := Packet send: 'This packet travelled to' to: #lpr.

S.Ducasse 24 Objects Send Messages Message: receiver : 1 (an instance of SmallInteger) selector: #+ arguments: 2 Message: lpr nextNode: macNode receiver: lpr (an instance of LanPrinter) selector: #nextNode: arguments: macNode (an instance of Workstation) Message: Packet send: 'This packet travelled to' to: #lpr receiver: Packet (a class) selector: #send:to: arguments: 'This packet travelled to' and #lpr

S.Ducasse 25 Transmitting a Packet | aLan packet macNode|... macNode := aLan findNodeWithAddress: #mac. packet := Packet send: 'This packet travelled to the printer' to: #lpr. macNode originate: packet. -> mac sends a packet to pc -> pc sends a packet to node1 -> node1 sends a packet to node2 -> node2 sends a packet to node3 -> node3 sends a packet to lpr -> lpr is printing -> this packet travelled to lpr

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

S.Ducasse 27 NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'classVarName1' poolDictionaries: '' category: 'LAN' How to Define a Class?

S.Ducasse 28 How to Define a Method? message selector and argument names "comment stating purpose of message" | temporary variable names | statements accept: thePacket "If the packet is addressed to me, print it. Otherwise just behave like a normal node." (thePacket isAddressedTo: self) ifTrue: [self print: thePacket] ifFalse: [super accept: thePacket]

S.Ducasse 29 In Java In Java we would write void accept(thePacket Packet) /*If the packet is addressed to me, print it. Otherwise just behave like a normal node.*/ if (thePacket.isAddressedTo(this)){ this.print(thePacket)} else super.accept(thePacket)}

S.Ducasse 30 Summary What is a message? What is the message receiver? What is the method selector? How to create a class? How to define a method?