Richard A. O'Keefe
ok at cs.otago.ac.nz
Tue Jun 22 06:30:47 UTC 2004
Brian Rice <water at tunes.org> wrote:
I fully agree, but that's not a tight enough idiom.
How about repeatedTimes:, one method for characters to make
strings, one for objects to make arrays?
The obvious question is, "just how common is this operation, anyway?"
The only time I've ever wanted $c repeatedTimes: n, $c has been
Character space, and what I've _really_ wanted has been aStream space: n.
I strongly dislike Brian Rice's recommendation; there's an assumption here
that no-one ever wants an Array of Characters, or any other kind of
indexed collection than Array or String. We have one simple way to do
String new: n withAll: $c
ByteArray new: n withAll: 255
FloatArray new: n withAll: 1.0
Array new: n withAll: Character cr
OrderedCollection new: n withAll: (string last)
or whatever takes our fancy, and the name says pretty clearly what it does.
It really is an intention-revealing method name.
In contrast, #repeatedTimes: strongly suggests #timesRepeat: to me, so
if I see
x repeatedTimes: n
I am *definitely* going to misread this for the next couple of years as
n timesRepeat: x
But above all, why do we need a "tight idiom" for an operation so rare?
Maybe it's used a lot in Python, but the Smalltalk way to build up large
strings is via Streams.
More information about the Squeak-dev