Temporary variables

Norton, Chris chrisn at Kronos.com
Fri Jun 18 16:30:01 UTC 1999


Hi Pierre & company.

This thread started out a bit shaky, but it is wrapping up quite nicely.
Thanks to Peter Lount and Time Olson for publishing statistics (and code) on
the frequency of temporary variables.  They really help to put this issue
into perspective!  Clearly the majority of Smalltalk has been written with
"one method = one job to perform" in mind, which I think is a good thing.

I really have nothing new to add to the discussion, as I agree with most of
the people who described various ways to do away with extraneous temporary
variables, but I wanted to point out that in my experience, the only methods
I've run across that had a size problem of any kind were the "createViews"
methods that are generated by WindowBuilder Pro (I use WindowBuilder Pro
with VSE).  In my experience, code generators will make some generic
assumptions and they rarely produce code that is as tidy as I like it.  ;-)
In those special cases, I routinely break up the generated methods into
smaller ones.

There have definitely been times where I've written a long method to
initialize a GUI or a particularly complex object.  And I have written some
pretty long methods that describe a complex algorithm, but I generally try
to keep my methods small.  Most of my longest methods were written early on
in my Smalltalk career, and I suspect that if I were to go back and look at
that old code I'd shudder and spend the whole afternoon refactoring!  ;-)

BTW:  I can't recall a time when I've run out of temporary variables in any
language.

---==> Chris

PS>  On a side note, I think the code snippets that Peter and Tim wrote are
good examples of "practical" metrics tools that we should keep together in
some repository.  Every so often, people post a useful chunk of code to this
group.  Has anybody else given any thought to gathering up these metrics
tools and adding them to Squeak?

> -----Original Message-----
> From:	Tim Olson [SMTP:tim at jumpnet.com]
> Sent:	Friday, June 18, 1999 9:52 AM
> To:	Squeak
> Subject:	RE: Temporary variables
> 
> Ian Trudel wrote:
> 
> >btw, you have this temporary variables stats' workspace for Squeak?
> 
> s := SortedCollection sortBlock: [:a :b | a numTemps <= b numTemps].
> s addAll: CompiledMethod allInstances.
> t := s inject: Bag new into: [:b :c | b add: c numTemps. b].
> n := 0.0.
> t sortedCounts asArray do:
>      [:a |
>      n := n + a key.
>      Transcript show:
>           a value printString, ' ', a key printString, ' ',
>           ((a key * 100.0 / t size) roundTo: 0.01) printString , ' ',
>           ((n * 100.0 / t size) roundTo: 0.01) printString; cr]
> 
> temps     methods        %         cumulative%
> 0         7208           34.81     34.81
> 1         5876           28.37     63.18
> 2         2810           13.57     76.75
> 3         1583           7.64      84.39
> 4          961           4.64      89.03
> 5          701           3.39      92.42
> 6          446           2.15      94.57
> 7          319           1.54      96.11
> 8          216           1.04      97.16
> 9          155           0.75      97.9
> 10          99           0.48      98.38
> 11          95           0.46      98.84
> 12          70           0.34      99.18
> 13          42           0.2       99.38
> 14          24           0.12      99.5
> 16          24           0.12      99.61
> 15          22           0.11      99.72
> 17          13           0.06      99.78
> 22          12           0.06      99.84
> 19           8           0.04      99.88
> 18           7           0.03      99.91
> 20           5           0.02      99.94
> 21           5           0.02      99.96
> 23           5           0.02      99.99
> 25           2           0.01      100.0
> 24           1           0.0       100.0
> 
> top 10 methods:
> 
> 
> (0 to: 9) do:
> 	[:n |
> 	Transcript show: (s at: s size - n) who printString; cr]
> 
> (BalloonEnginePlugin fillBitmapSpanAA:from:to:at: )
> (BitBltSimulation 
> smoothPix:atXf:yf:dxh:dyh:dxv:dyv:pixPerWord:pixelMask:sourceMap: )
> (NewParagraph composeLinesFrom:to:delta:into:priorLines:atY: )
> (SoundRecorder segmentsAbove:normalizedVolume: )
> (BalloonEnginePlugin fillRadialIncreasingAA:ramp:deltaST:dsX:dtX:from:to: 
> )
> (BalloonMorph class string:for:corner: )
> (B3DScanner rgbstwFill:from:to:at: )
> (JPEGReadWriter idctBlockInt:component: )
> (ParagraphEditor inOutdent:delta: )
> (BitBltSimulation warpLoop )
> 
> 
> 
> 
>      -- tim
> 





More information about the Squeak-dev mailing list