A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1258.mcz ==================== Summary ==================== Name: Kernel-ct.1258 Author: ct Time: 15 August 2019, 12:11:10.7644 am UUID: fbc76d48-44ce-1c40-91f2-2c73171c7981 Ancestors: Kernel-mt.1257 [Proposal] Implement #isEmptyOrNil on Object Allows extended polymorphy. =============== Diff against Kernel-mt.1257 =============== Item was added: + ----- Method: Object>>isEmptyOrNil (in category 'testing') ----- + isEmptyOrNil + + ^ false! |
When would you use it? Two scenarios in which this might get used: 1. I expect a variable to contain a collection or nil (signifying that there is nothing to be enumerated); 2. I expect "any" kind of object to arrive in that variable. If my expectation in scenario 1 is not met due to a programming error, I would have previously noticed it early because of the ensuing MessageNotUnderstood: isEmptyOrNil. Not any more with this addition. Instead I will just get MessageNotUnderstood: do:, for example, when I try to use this non-Collection like a Collection. This might happen at a much later time if the object gets stored somewhere due to "not being empty". In scenario 2, what do I learn about my object if this answers false? That it is not nil and not an empty collection; there is still nothing that I can safely send to this kind of object except messages understood by all objects. To send the latter, I wouldn't have needed to run this test first. If the object is in fact empty or nil, I probably wouldn't keep it or send any further messages to it either because there is nothing in it. Hence I'm wondering when this would ever be a useful response by a non-Collection. And whether it is worth hiding or delaying some errors, as explained above. Am Do., 15. Aug. 2019 um 00:11 Uhr schrieb <[hidden email]>: A new version of Kernel was added to project The Inbox: |
In reply to this post by commits-2
-1 :-) Yet, it reminds of the interface I added in Vivide: anObject asList "=> { anObject }" nil asList "=> #()" someObjects asList "=> someObjects" aDictionary asList "=> { aDictionary }" aString asList "=> { aString }" aText asList "=> { aText }" aByteArray asList "=> "{ aByteArray }" aHashedCollection asList "=> aSequenceableCollection" aCharacterSet asList "=> aCharacterSet or aSequenceableCollection if not enumerable" And similar for #isList. :-) Makes working with collections of domain objects much easier. Best, Marcel
|
Okay, thanks for your feedback :)
-Christoph Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Donnerstag, 15. August 2019 10:39:18 An: gettimothy via Squeak-dev Betreff: Re: [squeak-dev] The Inbox: Kernel-ct.1258.mcz
-1 :-)
Yet, it reminds of the interface I added in Vivide:
anObject asList "=> { anObject }"
nil asList "=> #()"
someObjects asList "=> someObjects"
aDictionary asList "=> { aDictionary }"
aString asList "=> { aString }"
aText asList "=> { aText }"
aByteArray asList "=> "{ aByteArray }"
aHashedCollection asList "=> aSequenceableCollection"
aCharacterSet asList "=> aCharacterSet or aSequenceableCollection if not enumerable"
And similar for #isList. :-) Makes working with collections of domain objects much easier.
Best,
Marcel
Carpe Squeak!
|
Free forum by Nabble | Edit this page |