On Tue, Oct 16, 2012 at 7:46 PM, sergio_101 <[email protected]> wrote:

> i had a problem earlier, thinking that if i did a detect: on an
> ordered collection, and the item was not found, i would get back nil.
> it turns out that it throws an error..
>
> to get this to work, you use:
>
> detect:ifNone:
>
> my only question is... why is this so?
>
> what is the motivation behind throwing an error rather than returning nil?
>
> i guess i would like to understand the 'smalltalkiness' about this,
> just in case i run into something like this in the future..
>
>
Smalltalk tries to be explicit and not to put things under the carpet. So
in this case, it will throw an exception instead of returning nil.
If that is what you want, then you can always do  detect: [ ... ]  ifNone:
[ nil ]  and you will get the behavior you want.
So, forget for a moment all you background of any programming language you
have, why would you expect to return nil?  ;)
Anyway, we have to admit, there still places in Smalltalk where we return
nil instead of throwing an exception.


> thanks!
>
>
> --
> ----
> peace,
> sergio
> photographer, journalist, visionary
>
> http://www.ThoseOptimizeGuys.com
> http://www.CodingForHire.com
> http://www.coffee-black.com
> http://www.painlessfrugality.com
> http://www.twitter.com/sergio_101
> http://www.facebook.com/sergio101
>
>


-- 
Mariano
http://marianopeck.wordpress.com

Reply via email to