Notes
Slide Show
Outline
1
Smalltalk
  • Keith Alcock
  • TCS DevSIG
  • 3 February 2004
2
Contents
  • Introduction: What is Smalltalk?
  • Hands On: Dolphin Smalltalk
  • Conclusion: Resources
3
Introduction: What is Smalltalk?
  • Language
  • Characteristics
  • Implementation
    • Commercial
    • Open source



4
What is Smalltalk: Language
  • Syntax
    • object message
      • noun verb (you scram)
      • noun verb: object  (you read: aBook)
      • noun verb: object preposition: object (you give: theBook to: me)
    • Incompatibilities
      • ↑ for ^, ← for :=, {} for ##() in Squeak
      • namespaces in VW
  • Library
    • 10,000s of methods, 1,000s of classes
    • GUI development
      • Portable across OSes, not Smalltalks
      • Model View Controller (MVC) or Presenter (MVP) architecture
  • Standard
    • ANSI 1998
      • Errors and omissions
      • Backward compatibility issues
5
What is Smalltalk: Characteristics
  • Object oriented
    • Single inheritance
    • Zero or more protocols (interfaces)
  • Garbage collected
  • Dynamically typed
  • Reflective (supports reflection)
  • Image based
  • Virtual machine hosted
  • Integrated (with development environment)
  • Optimized for development speed over processing speed


6
What is Smalltalk: Commercial Implementations
7
What is Smalltalk: Free Implementations
  • Squeak
  • GNU Smalltalk
  • #Smalltalk
  • Pocket Smalltalk
  • Little Smalltalk
  • S# for AOS
8
Hands on: Dolphin Smalltalk
  • Language
  • Exercises
  • Environment
  • Applications
9
Dolphin Smalltalk: Language
  • Syntax
    • Literal objects
      • integer: 3
      • character: $a
      • string: ‘string’
      • symbol: #
      • array: #(1 2 3)
      • comment: “comment”
      • block: [ ]
    • Messages
      • Unary
      • Binary
        • = vs. ==
      • Keyword
    • Statements
      • Terminated with period.
      • ^
      • :=
      • cascades
    • Blocks
      • niladic: [ ] value
      • monadic: [ ] value:
      • dyadic: [ ] value:value:
    • Control flow
      • ifTrue: [ ].
      • ifFalse: [ ].
      • ifTrue: [ ] ifFalse: [ ].
      • [ ] whileTrue.
      • [ ] whileTrue: [ ].
      • [ ] whileFalse.
      • [ ] whileFalse: [ ].
      • do: [ ].
      • [ ] repeat.
      • timesRepeat: [ ].
      • no switch
    • Exceptions
      • [ ] on:do: [ ].
    • Order of evaluation
      • LR on demand (UBK?)
10
Dolphin Smalltalk: Language
  • Semantics
    • Methods are public
      • Can be flagged as private, but not enforced
    • Variables are protected
      • Require accessors for non-subclass access
    • Uninitialized variables are set to nil
    • Methods return a single value using ^ or implicitly return self
    • Blocks return the value of the last expression
    • Case follows conventions
      • Uppercase first letter for classes
      • Lowercase first letter for variables and methods
      • Camelcase thereafter


11
Dolphin Smalltalk: Language
  • Variables
    • Intrinsic
      • self
      • super
      • thisContext
    • Block
    • Method
    • Arguments
    • Instance
    • Class
    • Class instance
    • Pool
    • (Namespace)
    • Global
      • true
      • false
      • nil
      • Classes
12
Dolphin Smalltalk: Language
  • Structure
    • Statement
    • Method
    • Category
    • Protocol
    • Class
    • Package (Parcel)
    • (Namespace)
    • Application
13
Dolphin Smalltalk: Exercises
  • Control flow
    • before:do:
    • after:do:
    • beside:do

  • // C# code (imagine dot product of vectors)
  • string[] books=new string[]{
  • "Book1","Book2","Book3"
  • };
  • string[] authors=new string[]{
  • "Author1","Author2","Author3"
  • };


  • for (int i=0;i<books.Length;i++)
  • Console.WriteLine("Book: {0} Author: {1}",
  • books[i],authors[i]);



14
Dolphin Smalltalk: Exercises
  • FizzBuzz
    • Free code
    • Method
    • Class
    • Application

15
Dolphin Smalltalk: Environment
  • Windows
    • Workspace
      • Object playground
    • Transcript
      • stdout
    • Debugger
      • Test-first development
      • Allows code changes during execution
    • Inspector
16
Dolphin Smalltalk: Environment
  • Browsers
    • Classes
    • Packages
    • Protocols
    • Resources
    • Pool Dictionaries
    • Source
17
Dolphin Smalltalk: Environment
  • Files
    • *.img
      • Image
    • *.sml
      • Source
    • *.chg
      • Changes
    • *.pac, *.pak
      • Packages
    • *.st
      • Code
    • *.cls
      • Class

18
Dolphin Smalltalk: Environment
  • Tools
    • Prepackaged
      • SUnit
      • Refactoring support
      • ActiveX/COM
      • ADO and ODBC
    • Contributed
      • DSDN (documentation and newsgroup archives)
      • Chunk browser
      • Profiler

19
Dolphin Smalltalk: Applications
  • Spelling
    • MutsunParser (detector)
    • SpellChecker (corrector)
  • GUI
    • ReadSmartOptions (example GUI)
  • Development
    • MyPackageBrowser
      • Export to RTF or package script, metrics, diagrams
    • MyClassBrowser
      • Export or view as RTF, metrics, edit definition, browse variables
  • Games
    • Equation game
20
Conclusion: Resources
  • Books
  • Web sites
  • Newsgroups
21
Resources: Books
  • The Art and Science of Smalltalk, Simon Lewis
  • Smalltalk Best Practice Patterns, Kent Beck
  • Smalltalk with Style, Suzanne Skublics et al.
  • The Design Patterns Smalltalk Companion, Sherman R. Alpert, et al.
  • The Dolphin Smalltalk Companion, Ted Bracht
  • Squeak: Object-Oriented Design with Multimedia Applications, Murk Guzdial


22
Resources: More books
  • Smalltalk, Objects, and Design, Chamond Liu
  • Smalltalk 80: The Language, Adele Goldberg
  • Object-Oriented Implementation of Numerical Methods: An Introduction with Java & Smalltalk, Didier Besset
  • Kent Beck’s Guide to Better Smalltalk: A Sorted Collection, Kent Beck
  • Squeak: A Quick Trip to ObjectLand, Gene Korienek


23
Resources: Web sites
  • Why Smalltalk?
    • www.whysmalltalk.com
  • Smalltalk Industry Council
    • www.stig.org
  • Smalltalk.org
    • www.smalltalk.org
  • Vendors’ web sites
  • My web site (for slides and code)
    • http://www.keithalcock.com


24
Resources: Newsgroups
  • General
    • comp.lang.smalltalk
    • comp.lang.smalltalk.dolphin
    • comp.lang.smalltalk.advocacy
  • news.totallyobjects.com
    • comp.lang.smalltalk.mt
    • comp.lang.smalltalk.objectstudio
  • news.software.ibm.com
    • ibm.software.vasmalltalk