Temporary variables

Michel Tilman mtilman at acm.org
Sun Jun 20 12:02:25 UTC 1999


Out of curiosity I checked a large part of our framework code and got the
following results:

Total number of methods checked: 20170

 0 temps: 17475 methods
 1 temp:  1747 methods
 2 temps: 502 methods
 3 temps: 243 methods
 4 temps: 101 methods
 5 temps: 37 methods
 6 temps: 21 methods
 7 temps: 11 methods
 8 temps: 14 methods
 9 temps: 5 methods
 10 temps: 1 method
 11 temps: 6 methods
 13 temps: 5 methods
 14 temps: 2 methods

0.996777 % of the methods have 5 temps or less; 65 methods have 6 temps or
more, with a maximum of 14. I had a quick look at the 44 methods having 6 or
more temps. All of these methods are rather longish and (at first sight) can
rather easily be split up in smaller (and more readable) pieces of code.
Most of these were written by newbies (both in Smalltalk and professional
development), some by more experienced developers (we get sloppy once in a
while, sigh...).

We did not enforce any specific rules with regards to using temporaries (but
I completely agree with Ralph, overall consistency of style IS important,
certainly when you work in a team: it can save you a lot of time when the
original developer is no longer available; code should be written with the
reader in mind, the days of the 'Lone Ranger' developers are gone).

So my tentaive (and very un-scientific) conclusion is: if you combine the
very natural feel of Smalltalk with a developer who had a good education /
background in computer science and has some common sense, it is hard to
write code that needs all these variables (e.g. it is very easy AND natural
to rewrite the long 'notes' example into a much more readable one that
requires only 1 temp; just make the implicit patterns in the code a bit more
explicit).

PS. On a more scientific note: one has to be careful in extracting the
number of (intentional) temps from the compiled code, as some of these may
be generated by the compiler.


michel

http://users.pandora.be/michel.tilman





More information about the Squeak-dev mailing list