Hi Aliaksei, On Wed, May 20, 2015 at 12:55 PM, Aliaksei Syrel <[email protected]> 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? (and for modern kids it looks ugly too). > Take a look how many languages already support ??: > C#, Swift, PHP7 (yes, these php-coders had to wait until 7th version), > JavaScript, Groovy (they name it Evil Operator), Objective-C. > > But yes, nils are evil :) > > Blocks are of course better, because they are lazy and don't get executed > if value is not nil - complete opposite to null coalescing operator. > ifNil:, ifNotNil:, ifNotNil:ifNil: and ifNil:ifNotNil: all get inlines as per ifTrue: et al, so no blocks are created The only overhead is syntactic. > > Cheers, > Alex > > On Wed, May 20, 2015 at 9:41 PM, Sven Van Caekenberghe <[email protected]> > wrote: > >> Yes, #ifNil: is almost the same (except the #value): >> >> |default1 default2 default3 default4 | >> default1 := nil. >> default2 := nil. >> default3 := 'foo'. >> default4 := 'don''t care'. >> default1 ifNil: [ default2 ifNil: [ default3 ifNil: [ default4 ] ] ] >> >> => 'foo' >> >> > On 20 May 2015, at 21:38, Damien Pollet <[email protected]> >> wrote: >> > >> > …ifNone: is a nice idiom, but not always available (in which case, we >> should think about introducing it) >> > >> > ?? is basically an infix but eager version of #ifNil:, IMHO a pragmatic >> thing to have; could be quite handy. >> > My only fear is that it could encourage the use of nil instead of >> proper Null Objects… and here we start bikeshedding >> > >> > On 20 May 2015 at 21:31, Sergio Fedi <[email protected]> wrote: >> > >> > In my experience those situations end up been handled by collections, >> detect:ifNone: which even handles the case when all defaults are nil. >> > >> > But maybe that idiom is very common in another situations. >> > >> > >> > >> > -- >> > Damien Pollet >> > type less, do more [ | ] http://people.untyped.org/damien.pollet >> >> >> > -- best, Eliot
