Bug? Inconsistency?: false ifTrue: [] ==> nil

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Wed Jan 26 11:39:04 UTC 2000


Up to now I thought the discussion was pointless, but I think I now see
what the inconsistency is.

All of these methods do return the block's value that is given as a
parameter (with nil being the value of an empty block):
	ifTrue:
	ifFalse:
	ifTrue:ifFalse:
	ifNotNil:
	ifNil:ifNotNil:
BUT
	ifNil:
does return the receiver (if it is not nil). So this really is an
inconsistency. When looking at senders of ifNil: there are two kinds. Most
of the time it's just an abbrevation for "isNil ifTrue:", ignoring the
return value. Only some do make use of the elegant built-in "yourself".

So for sake of consistency, ifNil: should return nil for any object except
for nil, which would make it a shortform for "ifNil: aBlock ifNotNil: []".
The receiver-returning variant should be named yourselfOrIfNil:.

BUT since consistency does not always have the highest priority, it's
(IMHO) okay to alias yourselfOrIfNil: and ifNil: because both usages don't
conflict. If this really bothers someone we'd need to invent a short
selector for yourselfOrIfNil:. (We can not, however, change the return
value of ifTrue: and co. This is just standard.)

  -Bert-





More information about the Squeak-dev mailing list