> On 05 Jan 2015, at 5:37 , Henrik Johansen <[email protected]>
> wrote:
>
>
>> On 05 Jan 2015, at 5:07 , Sebastian Sastre <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>>
>>> On Jan 5, 2015, at 1:48 PM, Henrik Johansen <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>>>
>>>> On 05 Jan 2015, at 4:20 , Sebastian Sastre <[email protected]
>>>> <mailto:[email protected]>> wrote:
>>>>
>>>> Ah Henry but you are making the code to know if it’s a collection or not,
>>>> I talking about making the code specifically to ignore that.
>>>>
>>>> Why that would lead to "bad code"? can you elaborate or put examples
>>>> instead of adjectives?
>>>>
>>>
>>> I did that already:
>>
>> I took a look at the thread and I don’t see examples of bad code
>>
>> I’m still curious about what you mean by that
>>
>
> Are you joking?
> I quoted the elaboration on what I mean by bad code...
>
> Cheers,
> Henry
Just in case there's something weird with your mail client, it was:
"it will lead to "are you a collection or single instance?" checks in almost
every user of said variable."
Which is unneccessary pain compared to using a collection with a single entry
if that's what you mean instead, and have all users expect a collection of
items to deal with.
So you'd do:
stuff: aCollection
stuff := aCollection ifNilOrEmpty: ["Default collection" #(1 2 3)]
which will raise an error if you pass in, say, Object new as pishPosh, instead
of leaving each user of stuff to determine whether stuff is a collection, an
object, or nil.
Of course, you can still do nonsense like
stuff := aCollection ifNilOrEmpty: [42]
but at least *that* problem is easier to pinpoint when later, a debugger with a
user of stuff that expected it to be a collection pops up.
If the origin of stuff as a single instance is lost to the mists of time (say,
Object implements ifNilOrEmpty: and someone called stuff: with an Object
without error), it's easier to end up with a solution of "fixing" the use to
(stuff isKindOf: Collection) "or is that isCollection?"
ifTrue: ["Code handling each entry"]
ifFalse: ["Code handling single instance"]
And now there's two stinks.
Cheers,
Henry