[sbe-discussion] Re: Question raised by SBE alternative coding
oscar at iam.unibe.ch
Mon Dec 10 17:38:57 MET 2007
If you look at the code, you will see that they are different, but
My guess is it makes no appreciable difference.
Generally you should not worry about performance too much, and only
when it is a problem, run some benchmarks, instrument your code,
identify bottlenecks and optimize.
You should focus on what you want to model rather than on how it is
Hope that helps.
[PS: I moved this thread back to the sbe-discussion list.]
On Dec 10, 2007, at 17:21, Doug Edmunds wrote:
> I am looking at pages 59-60 (pdf pages 71-72)
> On one page you have:
> send the message to:do: to an number
> n := 0.
> 1 to: 10 do: [ :counter | n := n + counter ].
> n ---> 55
> and on the other you have
> 1 to: 10 represents the interval from 1 to
> 10. Since it is a collection, we can send the message do: to it.
> n := 0.
> (1 to: 10) do: [ :element | n := n + element ].
> n −--> 55
> The first approach (to:do) shows up in the system browser
> under Category Kernel Numbers, Class Magnitude -> Number
> The second approach (to:) followed by (do:)
> also has (to:) under Category Kernel Numbers, Class Magnitude ->
> but (do:) by itself shows up under Category Collections-Sequences,
> Class Interval
> My question is twofold:
> 1. Does squeak process these two approaches differently
> (using different bits of code)?
> 2. If processed differently, is one preferred to the other (for speed,
> or for other reasons)?
> -- Doug Edmunds.
More information about the Sbe-discussion