On Wed, May 20, 2015 at 12:55 PM, Aliaksei Syrel <alex.sy...@gmail.com>
wrote:

> Check for the nil value should be banned in my opinion. There are
>> well-known techniques to not have to use it (e.g., Null-object pattern).
>
> Absolutely agree! :)
>
>  My only fear is that it could encourage the use of nil instead of proper
>> Null Objects
>
> Sometimes it's impossible to always have Null Object in first place and we
> still have to do something like this:
>
> default1 ifNil: [ "Null object" ].
>
>
> I even saw in many places
>
> values
>>   ^ values ifNil: [ OrderedCollection new ]
>
>
> And it perfectly works. However, usage of blocks for such simple checks
> looks like overhead, isn't it?
>
<snip>

Block may be overkill - but an infix, at least in classic smalltalk, means
that both sides of the operator get's evaluated.

So,
values
   ^ values && OrderedCollection new

would generate a new OrderedCollection every time it is called!.  Even more
overkill.

Or, if you use it for lazy initialization like:
values
   ^ values && (values := OrderedCollection new)
you would keep re-initializing values.

Try loading those messages and then doing:

a := Array with: 'Original Object'  " ==> #('Original Object') "
a && (OrderedCollection new)  " ==> #('Original Object') "
a  " ==> an OrderedCollection() "

Without more extensive changes than just adding  this, we'd be setting up
users for a huge amount of trouble in the future.

-cbc

Reply via email to