OrderedCollection>before:ifAbsent:
Jim Menard
jimm at io.com
Sat Apr 30 19:14:15 UTC 2005
On Apr 30, 2005, at 12:05 PM, Thomas Koenig wrote:
> Patch 6159 in 3.9 has the fix (this can also be applied to 3.7)
> SequenceableCollection>>before: target ifAbsent: exceptionBlock
> "Answer the receiver's element immediately before target. Answer
> the result of evaluating the exceptionBlock if target is not an
> element
> of the receiver, or if there are no elements before it."
>
> | index |
> index _ self indexOf: target.
> ^ (index == 0 or: [index == 1])
> ifTrue: [exceptionBlock value]
> ifFalse: [self at: index - 1]
Thank you. A question: how was it decided that the comment was correct
and the code was wrong? I ask for two reasons, one practical and one
philosophical: (1) Will it break anybody's code to change this code?
(2) Is there a unit test that covers this, and if so what was it
testing?
(The topic of code "versus" comments has been discussed this past week
on ruby-talk.)
Jim
--
Jim Menard, jimm at io.com, http://www.io.com/~jimm/
"Don't eat crackers in the bed of your future or you'll get ...
scratchy!"
-- The Tick
More information about the Squeak-dev
mailing list
|