[ENH] ifNotEmptyCleans
Marcus Denker
denker at iam.unibe.ch
Thu Sep 30 11:56:58 UTC 2004
Am 30.09.2004 um 13:24 schrieb Avi Bryant:
>
> On Sep 30, 2004, at 12:41 PM, stéphane ducasse wrote:
>
>> For me I do not understand what it means to require an argument, in
>> this case this is not
>> ifNotEmpty: [do that]
>> but ifNotEmpty: [do that with self]
>> and the message does not tell that at all
>>
>> and why we have that for ifNotEmpty and not for ifTrue: and isNil:
>
> Because in the case of ifTrue: and ifNil: (as well as ifFalse:), if
> the block is evaluated then you know exactly what the receiver is, so
> there's no need to pass it in.
> This is also mostly true for #ifEmpty:, in that you know that you've
> got an empty collection, and that's probably all you care about. In
> the case of #ifNotNil: or #ifNotEmpty:, however, there are interesting
> things about the receiver (for #ifNotNil:, what the instance is, for
> #ifNotEmpty:, what instances it contains) that you *don't* know, and
> so passing the receiver into the block is very useful.
>
> I generally agree with you about the message names, in that I'd rather
> see ifNotEmptyDo: (to match #ifNotNilDo:) as a distinct method from
> #ifNotEmpty:. However, there's a compatibility issue here - other
> dialects expect #ifNotNil: and #ifNotEmpty: to take a 1-arg block, and
> we should probably follow suit. As it is I have to avoid using either
> message if I want my code to be portable, which is a shame.
>
So I think the following would be a good compromise:
1) allow 0- and 1-arg block for ifNotEmpty: and ifNotNil: for
compatibility
2) provide ifNotEmptyDo: to be used. (there is already ifNotNilDo:).
Marcus
More information about the Squeak-dev
mailing list
|