|
|
Web
Log Stats Lesson 10
|
|
| Table
of Contents | Lesson
9 | Lesson 11 |
|
|
As you become more experienced in writing Smalltalk code,
you will be using the System Browser more and more and the Workspace
less and less. However, at this point in our evolution of writing Smalltalk
code, we are still using the Workspace for the majority of our work
then moving it to the System Browser and using it to create new
methods. There's nothing wrong with this method - we will do that again in
this lesson. The Workspace will become more of a place for testing
small snippets of code (to see how they work) before moving them into your
methods. But for now, it's a good learning exercise. |
|||
|
|
In this lesson, we'll take code from
the Workspace (which collects page counts from a log file) and move it into
new methods of the WebLog class so that you can perform this on not just one
log file but for as many as there are in a given directory. Since a lot of
groundwork has already been done (categories, classes and protocols), this
lesson will much shorter (and hopefully) easier than the first time you did
this. |
|||
|
|
1. Launch the System Browser
(from the main VisualWorks Launcher window, click the fourth button on
the Toolbar or select the menu option Browse >> System). showPageCounts: aFile 5. Now <Operate-Click>
in the bottom pane and select Accept. The showPageCounts:
method will appear in the Method pane. getLogFilesForPageCounts 7. Now <Operate-Click>
in the bottom pane and select Accept. The getLogFilesForPageCounts
method will appear in the Method pane. startPageCount 9. Now <Operate-Click>
in the bottom pane and select Accept. The startPageCount method
will appear in the Method pane. WebLog new startPageCount Highlight all of this text, <Operate-Click>
and select Do it. |
|||
|
|
It's a fact of life that software never stands still.
People always want more enhancements and even functional specifications can
change either during or after development. This is no exception. |
|||
|
|
12. Make sure the Instance tab
above the protocol pane is selected. Click (select) the private
protocol and click (select) the showPageCounts: method. Make the
following changes: showPageCounts: aFile 13. Now <Operate-Click>
in the bottom pane and select Accept. This will "re-compile"
the code you just entered. Barring any typos, if no dialog boxes popped up
(i.e. it looked as though nothing happened), then Smalltalk liked the code
change you made and compiled it. WebLog new startPageCount Highlight
all of this text, <Operate-Click> and select Do it.
16. Open a workspace and enter the
following: WebLog new startPageCount Highlight all of this text, <Operate-Click>
and select Do it. |
|||
|
|
Those code changes did quite a bit. Let's look at
them and make sure you understand what they do. xFound := (line findString: '.asp'
startingAt: 1) +
1 to: 10 do: [ :each | out cr;
nextPutAll: (sort at: each) printString.].
|
|||
|
|
Summary
Learning
how to move working code from a single Workspace into the class
library (by creating your own classes and methods) is big step. It challenges
your ability to know what's really going on especially when you split it into
separate parts and find a way to get them working together again. This, like
any other skill, becomes easier with more practice.
|
| Table
of Contents | Lesson
9 | Lesson 11 |