CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of...

14
CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones

Transcript of CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of...

Page 1: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

CS 403: Programming Languages

Lecture 5

Fall 2003

Department of Computer Science

University of Alabama

Joel Jones

Page 2: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 2

Outline

Introduction to Smalltalk—What, Why, How

Introduction to Squeak

Page 3: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 3

What is different about Smalltalk?

Everything is an object A real integrated development

environment Carefully integrated classes and syntax Dynamically typed Simple syntax

Page 4: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 4

Why learn Smalltalk? Nobody uses it. Yeah, nobodys like:

FedEx Ericsson Chrysler Deutsche Bank Dunn and Bradstreet Wisconsin Department of

Revenue Geico Direct John Deere

Texas Instruments Nokia Mitsubishi Volkswagen Bell Atlantic NYNEX Bell South MCI USWest

Page 5: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 5

History of Smalltalk

A few links http://www.ayers.je/smalltalk/smalltalkhistory

.html http://www.mojowire.com/

TravelsWithSmalltalk/DaveThomas-TravelsWithSmalltalk.htm

Page 6: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 6

Are you serious? But hopefully you will get a feel for why I

like Smalltalk so much and Why we will be looking at Smalltalk a little

further

Will I be a good Smalltalk programmer by the end of the lecture?

Page 7: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 7

Why do I care about the properties mentioned earlier? Carefully integrated classes and syntax

for (Iterator i = myCollection.iterator(); i.hasNext(); ) { ItemType myItem = (ItemType) i.next(); myItem.something();}

myCollection do [:myItem | myItem something]

Java

Smalltalk

Page 8: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 8

Why do I care about the properties mentioned earlier? Everything is an object

for (int i = 0; i < myArray.length; i++) { ItemType myItem = myArray[i]; myItem.something();}

myArray do [:myItem | myItem something]

Java

Smalltalk • Pair Up:

• What other property is exhibited here?

Page 9: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 9

How the heck did that Smalltalk code work? Simple stuff first

myItem something is a simple message send with no arguments

A little harder myCollection do: [ … ] is a message send

with one keyword with an argument Even harder

[…] is a block, which is a closure, a thunk with arguments, an anonymous inner class, a function pointer with lexical capture, etc.

Page 10: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 10

Everything is an Object I wasn’t kidding The block is an object All loops and control structures in

Smalltalk are objects Once you learn them, the collection

classes mean you don’t have to write the same kind of loop infrastructure over and over again

Page 11: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 11

Control methods Collections

do: select: collect: detect: detect: ifNone: inject: into: reject:

Boolean ifTrue: ifTrue: ifFalse: ifFalse: ifFalse: ifTrue:

Page 12: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 12

What is the Smalltalk programming environment like?

We will be using Squeak, a freely available implementation

We’ll be looking at it right now. A quick reference can be found at:

http://www.mucow.com/squeak-qref.html

Page 13: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 13

References

Download implementation, etc. www.squeak.org

www.smalltalk.org Smalltalk idioms and conventions

http://www.angelfire.com/tx4/cus/notes/smalltalk.html

Page 14: CS 403: Programming Languages Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Lecture 5 ©2003 Joel Jones 14

Next two classes

I will be out of town Meet at normal class time and place Someone will have lab assignments for

you to do on Smalltalk http://www.mucow.com/squeak-qref.html