13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.

Slides:



Advertisements
Similar presentations
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz.
Advertisements

8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
12. Common Errors, a few Puzzles. © O. Nierstrasz P2 — Common Errors, a few Puzzles 12.2 Common Errors, a few Puzzles Sources  Cay Horstmann, Computing.
ESE Einführung in Software Engineering 7. Modeling Behaviour Prof. O. Nierstrasz.
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.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Autumn Semester 2009.
Principles of Object-Oriented Software Development The language Smalltalk.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Autumn Semester 2007.
Object-Oriented Reengineering Patterns and Techniques Prof. O. Nierstrasz Prof. S. Ducasse T.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
7. Understanding Classes and Metaclasses. © Oscar Nierstrasz ST — Understanding Classes and Metaclasses 7.2 Roadmap  Metaclasses in 7 points  Indexed.
12. Common Errors, a few Puzzles. © O. Nierstrasz P2 — Common Errors, a few Puzzles 12.2 Common Errors, a few Puzzles Overview  Common errors … —Typical.
ESE Einführung in Software Engineering N. XXX Prof. O. Nierstrasz Fall Semester 2009.
© Oscar Nierstrasz ST — Smalltalk Basics 2.1 Change sets  Make sure your changes are logged to a new change set.
The Software Composition Group Prof. O. Nierstrasz
13. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Summary, Trends, Research...  Summary: functional, logic and object-oriented.
6. Debugging. Birds-eye view © Oscar Nierstrasz ST — Introduction 1.2 It can be easier to talk to objects than to read classes — The system is alive.
ESE Einführung in Software Engineering X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
Stéphane Ducasse 1 The Taste of Smalltalk.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed lambda calculus.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
Metamodeling Seminar X. CHAPTER Prof. O. Nierstrasz Spring Semester 2008.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Programmierung 2 Object-Oriented Programming with Java Prof. O. Nierstrasz Sommersemester 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 
© Oscar Nierstrasz ST — Smalltalk Basics 2.1 Change sets  Make sure your changes are logged to a new change set.
Principles of Object-oriented Programming Programming Language Paradigms August 26, 2002.
ESE Einführung in Software Engineering X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
6. Debugging. © Oscar Nierstrasz ST — Debugging 6.2 Roadmap  Common syntactic errors  Common semantic errors  Encapsulation errors  Class/instance.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
N. XXX Prof. O. Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap Overview  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed.
12. Common Errors, a few Puzzles. © O. Nierstrasz P2 — Common Errors, a few Puzzles 12.2 Common Errors, a few Puzzles Sources  Cay Horstmann, Computing.
6. Debugging. © Oscar Nierstrasz ST — Debugging 6.2 Roadmap  Common syntactic errors  Common semantic errors  Encapsulation errors  Class/instance.
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.1 MakeMoney Corp. C*O of MakeMoney Corp. Our Vision  We invest in software  We do not know software 
OORPT Object-Oriented Reengineering Patterns and Techniques X. CHAPTER Prof. O. Nierstrasz.
CP — Concurrent Programming X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
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.
12. eToys. © O. Nierstrasz PS — eToys 12.2 Denotational Semantics Overview:  … References:  …
Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
3A-1 1 Introduction to Smalltalk History of Smalltalk The philosophy of Smalltalk:  “...we have a universe of well-behaved objects that courteously ask.
Tutorial: Squeak — An Open-Source Smalltalk Environment Oscar Nierstrasz scg.unibe.ch TOOLS Europe 2008 Zürich, July 1, 2008.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Object-Oriented Programming Lecture 13 – OO Programming, Spring CSE3302 Programming Languages,
7. Just In Time Compilation Prof. O. Nierstrasz Jan Kurs.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
Smalltalk for Unix & W i n d o w s Dennis Smith Cherniak Software Development Corporation.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
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.
3C-1 Identifiers Variables Literal Objects  Numbers  Characters  Strings Control Structure  Blocks  Conditionals  Loops Messages Defining New 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.
Aaron Bloomfield CS 415 Fall 2005
Smalltalk – a Pure (and first) OOPL
CS 331 Principles of Programming Languages
Introduction to Smalltalk
Let’s Talk about… Smalltalk.
Introduction to Smalltalk
CSE 3302 Programming Languages
Presentation transcript:

13. A bit of Smalltalk

© Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development with Smalltalk Smalltalk

© Oscar Nierstrasz 3 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development with Smalltalk Smalltalk

© Oscar Nierstrasz 4 The origins of Smalltalk Alan Kay’s Dynabook project (1968) Alto — Xerox PARC (1973) gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html Smalltalk

© Oscar Nierstrasz Smalltalk 11.5 Object-oriented language genealogy

© Oscar Nierstrasz Smalltalk 6 Smalltalk vs. C++ vs. Java SmalltalkC++Java Object modelPureHybrid Garbage collectionAutomaticManualAutomatic InheritanceSingleMultipleSingle TypesDynamicStatic ReflectionFully reflectiveIntrospection ConcurrencySemaphoresSome librariesMonitors ModulesCategories, namespaces NamespacesPackages

© Oscar Nierstrasz 7 Smalltalk-80 and Squeak Everything is an object Everything is there, all the time First windowing system with mouse First graphical IDE Smalltalk

© Oscar Nierstrasz ST — Introduction 1.8 What are Squeak and Pharo?  Squeak is a modern, open-source, highly portable, fast, full-featured Smalltalk implementation —Based on original Smalltalk-80 code  Pharo is a lean and clean fork of Squeak —

© Oscar Nierstrasz 9 Don’t panic! New Smalltalkers often think they need to understand all the details of a thing before they can use it. Try to answer the question with — Alan Knight. Smalltalk Guru Smalltalk “How does this work?” “I don’t care”.

© Oscar Nierstrasz 10 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development with Smalltalk Smalltalk

© Oscar Nierstrasz Smalltalk 11 Two rules to remember

Everything is an object © Oscar Nierstrasz 12 Smalltalk

Everything happens by sending messages © Oscar Nierstrasz 13 Smalltalk

© Oscar Nierstrasz 14 What is Smalltalk? Image Changes + Virtual machine Sources + Smalltalk

© Oscar Nierstrasz 15 Running Pahro Smalltalk

© Oscar Nierstrasz ST — Introduction 1.16 Mouse Semantics Select Operate Window

© Oscar Nierstrasz ST — Introduction 1.17 World Menu

© Oscar Nierstrasz 18 Standard development tools Smalltalk

© Oscar Nierstrasz 19 Debuggers, Inspectors, Explorers Smalltalk

© Oscar Nierstrasz 20 Do it, Print it, … You can evaluate any expression anywhere in Smalltalk. Smalltalk

© Oscar Nierstrasz 21 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development with Smalltalk Smalltalk

© Oscar Nierstrasz 22 Three kinds of messages > Unary messages > Binary messages > Keyword messages 5 factorial Transcript cr raisedTo: 10 modulo: 5 Transcript show: 'hello world' Smalltalk

© Oscar Nierstrasz 23 Precedence 2 raisedTo: factorial * (2 * 3) 128 9(!) 7 First unary, then binary, then keyword: Use parentheses to force order: 2 raisedTo: (1 + (3 factorial)) Same as: Smalltalk

© Oscar Nierstrasz 24 A typical method in the class Point <= aPoint "Answer whether the receiver is neither below nor to the right of aPoint." ^ x <= aPoint x and: [y <= aPoint y] <= true Method nameArgumentComment Return Keyword message Instance variable Block Binary message Smalltalk

© Oscar Nierstrasz 25 Statements and cascades | p pen | p := pen := Pen new. pen up. pen goto: p; down; goto: p+p Temporary variables Statement Cascade Smalltalk Assignment

© Oscar Nierstrasz 26 Literals and constants Strings & Characters'hello' $a Numbers Symbols#yadayada Arrays#(1 2 3) Pseudo-variablesself super Constantstrue false Smalltalk

© Oscar Nierstrasz 27 Method Return  Use a caret to return a value from a method or a block  By default, methods return self max: aNumber ^ self < aNumber ifTrue: [aNumber] ifFalse: [self] 1 max: 2 2 Smalltalk

© Oscar Nierstrasz 28 Blocks  Use square brackets to delay evaluation of expressions ^ 1 < 2 ifTrue: ['smaller'] ifFalse: ['bigger'] 'smaller' Smalltalk

© Oscar Nierstrasz 29 Variables  Local variables are delimited by |var| Block variables by :var| OrderedCollection>>collect: aBlock "Evaluate aBlock with each of my elements as the argument." | newCollection | newCollection := self species new: self size. firstIndex to: lastIndex do: [ :index | newCollection addLast: (aBlock value: (array at: index))]. ^ newCollection (OrderedCollection with: 10 with: 5) collect: [:each| each factorial ] an OrderedCollection( ) Smalltalk

© Oscar Nierstrasz 30 Control Structures  Every control structure is realized by message sends max: aNumber ^ self < aNumber ifTrue: [aNumber] ifFalse: [self] 4 timesRepeat: [Beeper beep] Smalltalk

© Oscar Nierstrasz 31 Creating objects  Class methods  Factory methods OrderedCollection new Array with: 1 with: 2 1/2 a Point a Fraction Smalltalk

© Oscar Nierstrasz 32 Creating classes  Send a message to a class (!) Number subclass: #Complex instanceVariableNames: 'real imaginary' classVariableNames: '' poolDictionaries: '' category: 'ComplexNumbers' Smalltalk

© Oscar Nierstrasz 33 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development with Smalltalk Smalltalk

Seaside — a Smalltalk web development platform © Oscar Nierstrasz Smalltalk 34

Seaside demo © Oscar Nierstrasz Smalltalk 35

© Oscar Nierstrasz Smalltalk 36 What you should know!  What are the key differences between Smalltalk, C++ and Java?  What is at the root of the Smalltalk class hierarchy?  What kinds of messages can one send to objects?  What is a cascade?  Why does 1+2/3 = 1 in Smalltalk?  How are control structures realized?  How is a new class created?  What are categories for?  What are Factory methods? When are they useful?

© Oscar Nierstrasz Smalltalk 37 Can you answer these questions?  Which is faster, a program written in Smalltalk, C++ or Java?  Which is faster to develop & debug, a program written in Smalltalk, C++ or Java?  How are Booleans implemented?  Is a comment an Object? How would you check this?  What is the equivalent of a static method in Smalltalk?  How do you make methods private in Smalltalk?  What is the difference between = and ==?  If classes are objects too, what classes are they instances of?

License © Oscar Nierstrasz 38 Attribution-ShareAlike 2.5 You are free: to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. Smalltalk