[sbe-discussion] Re: Question raised by SBE alternative coding

Damien Cassou damien.cassou at gmail.com
Mon Dec 10 17:49:26 MET 2007


Hi,

in fact, #to:do: is much more efficient than #to: followed by #do:
(according to squeak-dev mailing list). The second approach creates an
interval object only required to iterate over it. The first approach
does not create anything.

2007/12/10, Oscar Nierstrasz <oscar at iam.unibe.ch>:
>
> Hi Doug.
>
> Good question.
>
> If you look at the code, you will see that they are different, but
> very similar.
>
> 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
> implemented.
>
> Hope that helps.
>
> Oscar
>
> [PS: I moved this thread back to the sbe-discussion list.]
>
> On Dec 10, 2007, at 17:21, Doug Edmunds wrote:
>
> > Hello,
> >
> > 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 ->
> > Number
> > 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)?
> >
> > Thanks.
> >
> > -- Doug Edmunds.
> >
>
>
> _______________________________________________
> Sbe-discussion mailing list
> Sbe-discussion at iam.unibe.ch
> https://www.iam.unibe.ch/mailman/listinfo/sbe-discussion
>


-- 
Damien Cassou



More information about the Sbe-discussion mailing list