Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.

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

Web Application Development Slides Credit Umair Javed LUMS.
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,
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 
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.
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
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.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
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.
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.
Copyright Curt Hill Variables What are they? Why do we need them?
Smalltalk in a.NET World How to write a Smalltalk compiler without writing a VM John Brant
Copyright © 2015 Curt Hill Java for Minecraft Those things you should know.
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.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 11 Categories of languages that support OOP: 1. OOP support is added to an existing language.
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.
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.
Stéphane Ducasse 1 Abstract Classes.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
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.
Definition of the Programming Language CPRL
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
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
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
Chap 2. Identifiers, Keywords, and Types
Let’s Talk about… Smalltalk.
Introduction to Smalltalk
CSE 3302 Programming Languages
Smalltalk on a Dime.
Presentation transcript:

Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell

Stéphane Ducasse5.2 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

Stéphane Ducasse5.3 Power & Simplicity: The 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

Stéphane Ducasse5.4 Language Constructs ^return “ comments #symbol or array ‘string [ ]block or byte array.separator and not terminator (or namespace access in VW7) ;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

Stéphane Ducasse5.5 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 Note is not an element of the syntax, but just a message sent to a number. This is the same for /, bitShift, ifTrue:, do:...

Stéphane Ducasse5.6 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:(...)

Stéphane Ducasse5.7 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

Stéphane Ducasse5.8 Class and Method Definition Revisited 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)

Stéphane Ducasse5.9 Method Revisited Normally defined in a browser or (by directly invoking the compiler) Methods are public Tomagoshi>>digest "Digest slowly: every two cycles, remove one from the tummy” (dayCount isDivisibleBy: 2) ifTrue: [ tummy := tummy -1]

Stéphane Ducasse5.10 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