The Presenters The Smalltalk...

15
Lecture 3 Object-Oriented Languages and Systems 1 The Presenters Ginny Ghezzo: Project Manager for IBM VisualAge Smalltalk and Level 3 support for the Application Builder Craig Chaney: Technical Lead on the Virtual Machine, Communications and Linux development The Smalltalk Environment There are a few important ways that Smalltalk is different then other languages: 1. The Simplicity The Smalltalk syntax fits on an “index card.” a. There are six reserved words in Smalltalk. b. There are three types of expressions. Smalltalk becomes a study of class libraries and not memorization of syntax 2. The Image The creation and execution of code take place in the same “object space” called an image. Smalltalk environments do not produce standalone executables for a program. 3. Development Cycle You do not need to compile and link your code. Any changes to the source code are immediately compiled into the classes in the image. This lends itself to incremental development. 4. All source code is visible Two benefits

Transcript of The Presenters The Smalltalk...

Page 1: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 1

The Presenters

• Ginny Ghezzo: Project Manager for IBM VisualAge Smalltalkand Level 3 support for the Application Builder

• Craig Chaney: Technical Lead on the Virtual Machine,Communications and Linux development

The Smalltalk Environment

There are a few important ways that Smalltalk is different then otherlanguages:

1. The Simplicity• The Smalltalk syntax fits on an “index card.”

a. There are six reserved words in Smalltalk.b. There are three types of expressions.

Smalltalk becomes a study of class libraries and notmemorization of syntax

2. The Image• The creation and execution of code take place in the same

“object space” called an image.• Smalltalk environments do not produce standalone

executables for a program.

3. Development Cycle• You do not need to compile and link your code.• Any changes to the source code are immediately compiled

into the classes in the image.• This lends itself to incremental development.

4. All source code is visible• Two benefits

Page 2: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 2

1. You get to see examples of code.2. You know exactly what a particular method is going to do

for you and return to you. You are browsing theenvironment to determine the class/methods to use

The Programming Cycle

1. Write classes and methods using the Browser Tools in theenvironment

2. Execute the code to test if it works. This is usually done inWorkspaces or Browsers.

3. Debug any problems you encounter in the debugger.

4. For Production Applications you would do another step calledpackaging.

VisualAge Smalltalk Enterprise V5.5.2

Downloadable at http://www.ibm.com/software/ad/smalltalk under thetopic “Download VisualAge Smalltalk Version 5.5.2”

Tools

System Transcript

• The main window in VisualAge Smalltalk.• One and only one System Transcript.

Workspaces

Workspaces are a simple text pane to try out code.

Page 3: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 3

• File -> New: Creates a new Workspace• File -> Open: Opens an existing Workspace

Three ways to interact with expressions …

• Execute: Evaluate the expression but do not display theresults.

• Display: Evaluate the expression and display the value

• Inspect: Evaluate the expression and open an Inspector onthe result.

Ø Execute, Inspect, Display are available anywhere you can type incode.

Inspector

A window in which one can see and manipulate an object.

• Exampleso Inspect 3+4o Inspect OrderedCollection with: ‘Smalltalk’

with: ‘is’ with: ‘good’.

• Changing the value of an object or its variableso Change the value directly with File->Saveo Change the value by executing methodso To bind the value of self to a variable use

Bind ‘self’ to selection

Page 4: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 4

• Some useful Inspector menu items:o File -> Revert: Changes the contents of the text

pane back to its previous contents.

o Variable -> Inspect: Brings up a new inspectorwindow on the selected object.

o Variable -> Update: If the object’s value haschanged since the inspector was opened or saved willdisplay the new value.

o Variable -> Browse Class: Brings up a browserthat displays the class definition

Browsers

Page 5: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 5

Task Browser(s)Add a new application Application Manager, Applications

Browser, Organizer

Change prerequisites for anapplication

Application Manager, Organizer

Add new classes to an application Applications Browser, ApplicationBrowser, Classes Browser,Hierarchy Browser, Organizer

See all classes for one application Application Manager, ApplicationsBrowser, Application Browser,Organizer

Add new methods to a class for oneapplication

Applications Browser, ApplicationBrowser, Classes Browser,Hierarchy Browser, Class Browser

Add new methods to a class for anyapplication

Applications Browser, ClassesBrowser, Hierarchy Browser

See all methods for a class for allapplications

Class Browser, Classes Browser,Hierarchy Browser

See all methods that use a specificmethod or that have the same name

Methods Browser

Inspect code and dictionaries Inspector

Find errors in code Debugger

Package applications into runtimeimages

Application Manager, ConfigurationMaps Browser, Packager ControlBrowser, Organizer

See what applications are in thelibrary

Application Editions browser,Configuration Maps Browser,Shadow Application Browser

See all editions and versions of acomponent

Application Editions browser, ClassEditions Browser, Method EditionsBrowser, Configuration MapsBrowser

Assign team members ownership ofspecific components

Application Manager, ConfigurationMaps Browser, Organizer

Configure components to supportmultiple platforms

Configuration Maps Browser,Application Editions browser

Find differences in code amongcomponents and editions of

Application Changes Browser,Changes Browser, Text Comparison

Page 6: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 6

components Browser

Analyze the performance of code Benchmark Workshop, MemoryMonitor

Applications Browser

• An Application is a group of related classes that are functionallyrelated and can be used as a unit. Every class in VisualAgeSmalltalk belongs to one application.

• A Prerequisite is an application that is required by anotherapplication

o Example: CommonFileSystem is a prerequisite to anyapplication that reads or writes to a file.

o Application Manager Browser Prerequisite Menu hastools to determine prerequisites

• A Subapplication is an application that is contained with in anapplication

o Used to separate Operating System Specific Codeo Subapplications are not used very often

To open use the tool menu and select Browse Applications:• The first pane lists all applications that are loaded.• The second pane lists the classes in that application.

Page 7: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 7

• The third pane lists the categories defined in the class• The fourth pane lists the method names in that category

To create an application, perform Application -> Create ->Application

• VisualAge Smalltalk creates a Class that is the same nameas the application.

To create a Class, perform Classes-> Add-> Subclass…• Directly add instance variables, class variables and pool

dictionaries• Can change the class you are subclassing from• Changing the name of the class will create a new class• Methods-> New Method Template• Change the methodPattern of an already created method

Ø Public and Private are solely for the convenience of developersand will not affect the access to methods during execution.

To create a Method,

To create a categories,• With a class highlighted, Categories-> Add• With a method highlighted, Method->Categories->Add

To Categories

Ø Categories are solely for the convenience of the developers andwill not affect the execution of the methods.

Useful menu options available in most browsers

Applications

• Find Application: Finds an application in the left handpane

• Find Class: Finds a class within the application selected

Classes

• Browse References: Allows you to see all referencesto various types of objects used by this class.

Page 8: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 8

• Browse Messages: Allows you to find thesenders/implementers of a method restricted to thehierarchy of the selected class.

• Browse Class: Opens the class browser on theselected class

• Browse Hierarchy: Opens the Hierarchy Browser onthe class. This will tell you all of the superclasses for theclass.

Categories

• Add: Adds a new category for this class• Rename: Allows you to change the name of the category

selected• Delete: Deletes the category. If any methods are in this

category they move to “Not Categorized”. This will notdelete any methods.

• Select All By Default: A toggle that when selectedwill highlight all categories when a class is selected.

Methods

• Visibility: Changes which methods will show up inthe method pane based on the level selected in thehierarchy.

• Browse Senders: Shows all methods that send theselected method

• Browse Implementers: Shows implementation of allmethods with the same name.

• Browse Messages: Shows all classes that send anymethod that this method sends.

• Load: Allows you to bring in a different edition of themethod.

Code Management

There are two parts of VisualAge Smalltalk

1. The Client, which is your development environment2. The Code Manager, which stores all of the code

a. Keeps a version of every saved change to a method

Page 9: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 9

b. Tracks which developer made the changec. Allows you to compare changes in your code

An Open Edition is a state that allows you to change a class orapplication. All methods are considered editions when saved.

Versioning instructs VisualAge to preserve a class or application’scontents. A version cannot be changed. A new edition must beopened to change the class or application.

Releasing instructs VisualAge to load that particular version of aclass or subapplication if anyone loads its containing application.

Exporting Applications

There are two ways to share code with other Managers.

1. File In/File Out: Creates a flat text file containing the sourcecode of any method, class or Application.

2. Import/Export: Creates a little manager with the Applicationcode.a. Creates a .dat file that can be shared with others.

ENVY\Smalltalk Debugger

The Debugger is displayed when an exception is thrown.

Page 10: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 10

The five panes of the debugger are:

1. Process List: Gives you a list of all of the processes you aredebugging.

2. Message Stack: The messages that were executing when thedebugger was opening

3. Variables: All visible variables including temporary variablesdefined in the current method.

4. Variable Values: The current value of the variables that areselected

5. Description Pane: The code for the method. The expressionsent is highlighted.

There are four ways you can step through the code in the stack.

1. Into: Displays the code and takes you into the methodselected.

2. Over: Executes the message without displaying the method’ssource.

3. Return: Execute the rest of the current method up to thereturn statement.

4. Resume: Continue the current process until it completes

Useful functions:

Page 11: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 11

• Processes->Debug Other… Shows a list of currentlyrunning processes and allows you to select them to bedisplayed in the debugger.

• Processes->Remove from list: Removes the selectedprocess from the list in the debugger but does not terminate theprocess.

• Processes->Terminate: Terminates a process andremoves it from the process list.

• Stack->Drop to Selected Frame: Restarts the executionfrom the top of the stack. Remember you are re-executingsome code and the effects of the first run have not beenundone.

There are five ways to get the debugger to come up

1. From the System Transcript under the Tools Menu

2. By executing a ‘self halt’. This is most commonly used whenyou need to stop within a workspace script

3. An exception is thrown because of a code problem

4. Clicking on the User Exit Button

5. A breakpoint is encountered.

Initial Windows

When you start the VisualAge Smalltalk environment (abt.icx)and have connected to the code repository, three windows willbe opened.

VisualAge Smalltalk – Click Here to Interrupt Execution

Page 12: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 12

System Transcript

The system transcript is a special instance of Workspace withthree unique features.

• Can access the HTML help through the help menu.• Access various browsers, the debugger, view your

breakpoints and access to your code manager from the toolsmenu

• Is accessible as a global variable, Transcript, for printingmessages to.

VisualAge Organizer

The VisualAge Organizer is a graphical browser of applications

Page 13: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 13

• Has all of the capability of the Application Browser whenfull menus are on.

• Give you access to special editorso Composition Editor: Visual code Builder through

parts.o Script Editor: Add Smalltalk code in methods (like

the Class Browser)o Public Interface Editor: Define interfaces into

created parts and generate scripts\methods

Additional Information

Newsgroup: ibm.software.vasmalltalk• Please use this for any and all questions about VisualAge

SmalltalkE-mail support list: [email protected]• Please use this for questions that arise in the course of doing

your homework.

Documentation

• Our books are available in PDF format at http://www-4.ibm.com/software/ad/smalltalk/library/v55docs.html

Page 14: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 14

• Searchable helps and books are installed with the product.

Installation

• Will probably not need the additional features.• Downloading from the Web lets you choose 2 big files (client

and manager) or 14 small files.

Getting Started

• VisualAge Smalltalk Getting Started: A basic applicationusing visual parts.

• How Do I Help…: Has some useful basic information onapplications, packaging, etc.

Other Dialects

Page 15: The Presenters The Smalltalk Environmentpeople.engr.ncsu.edu/efg/517/f01/syllabus/lectures/lec3.pdf · The Smalltalk Environment There are a few important ways that Smalltalk is different

Lecture 3 Object-Oriented Languages and Systems 15

For more information on the various dialects of Smalltalk seewww.stic.org, www.smalltalk.org or www.whysmalltalk.org

Examples from Class

Methodsbalance: anAmount

balance:= anAmount

balance^balance

withdraw: anAmountself balance: (self balance – anAmount)

deposit: anAmountself balance: (self balance – anAmount)

isNegative^self balance < 0

openAccount: initialBalance^self new balance: balance; yourself.

Scripts

| ticker |ticker := OrderedCollection with: 1.ticker inspect.[ 20 timesRepeat: [ ticker at: 1 put: (tickerfirst + 1). (Delay forSeconds: 1) wait. ] ]fork.

[ [ true ] whileTrue: [ (Delay forSeconds: 1)wait ] ] forkNamed: 'Our cool delay loop'