2007/10/15, Chad Perrin <perrin / apotheon.com>:
> On Tue, Oct 16, 2007 at 04:02:35AM +0900, Gerardo Santana G?mez Garrido wrote:
> >
> > nil has other uses besides representing nothing: it means false in a
> > boolean context.
>
> What purpose do you propose for nil if it isn't differentiated in
> behavior from false in that manner?  Shouldn't we then either replace all
> instance of false with nil or all instances of nil with false?


I'm sorry, I didn't understand your questions.


>
>
> >
> > If nil
> > Under that logic then zero must evaluate to false, just like C and Python does.
> > I don't agree with that, of course.
>
> No . . . 0 would evaluate as 0 or true, while nil would evaluate as
> false.  Similarly, "1" evaluates as "1", but "1".to_i evaluates as 1.
> That's the point of a method like to_i, as far as I can tell.

Dismiss that paragraph please. Somehow it got chopped. I can't even
remember what was my point there :)  Sorry.


> >
> > Because if I want 0 would expect or send 0, not nil.to_i.
> > Because it doesn't make sense to me that nil, which means false also,
> > can be represented as zero, when zero doesn't mean false, but true.
>
> Trans made the point that eliminating to_i from the nil lineup of methods
> would suddenly result in a lot of ( x ? x.to_i : 0 ) being used.  It
> seems to me that nil.to_i is convenient, makes a certain amount of
> logical sense, and doesn't actually introduce unexpected behavior except
> in pathological edge-cases.  Am I missing some non-pathological, non-edge
> cases?


I think it's a matter of taste then?

If you read the pages I linked to in my first post you'll see that
nil.to_i => 0 was unexpected by some people. Even a Ruby on Rails
developer was bitten by that.


> >
> > Chad Perrin wrote:
> > > How about any circumstance in which one performs some kind of counting
> > > function in code, and operates on the number of whatever is counted,
> > > where no specific value is yet applied to the variable in question until
> > > the first item is counted?
> >
> > I don't think I understood you. Correct me plese, but I think you're talking
> > about an accumulator? In that case, you should start from zero, not nil.
>
> . . .

What?

Sometimes I have a problems with your language. What does that ellipsis mean?

-- 
Gerardo Santana