[Interval Problem] 2 cents

Andres Valloud sqrmax at cvtci.com.ar
Fri Jul 30 22:51:32 UTC 1999


Hi.

> > do: aBlock
> >
> >         | aValue |
> >         aValue _ start.
> >         step < 0
> >                 ifTrue: [[stop <= aValue]
> >                                 whileTrue:
> >                                         [aBlock value: aValue.
> >                                         aValue _ aValue + step]]
> >                 ifFalse: [[stop >= aValue]
> >                                 whileTrue:
> >                                         [aBlock value: aValue.
> >                                         aValue _ aValue + step]]
> >
> > I do not see any accessor there.
> But you should ;-)

I did not code the Interval class!!! And furthermore, I don't think I
would like accessors in Interval.

But ok, next time I'll save my 2 cents.

> A really objectified version would go even further like
> 
> do: aBlock
>         [self atEnd] whileFalse: [
>                 aBlock value: self currentValue.
>                 self step]
> 
> This would even increase performance because you could optimize
> different atEnd and step methods for e.g. ints and floats or points etc.

No way!... #atEnd forces a message send, #< is not a message send with
regular ints and floats because it's done by the VM as a bytecode. Your
argument does not apply to all (most common) cases. And would you make
subclasses of Interval for different types of start and end, or would
you optimize #< instead?

Andres.





More information about the Squeak-dev mailing list