From: Robert Klemme Date: 2004-05-19T19:23:47+09:00 Subject: Re: Zero is true ... whoda thunk? "Michael Geary" schrieb im Newsbeitrag news:10allar4vlk2092@corp.supernews.com... > Claus Spitzer wrote: > > I believe the behavior was borrowed from Smalltalk (or was > > it Scheme? one of them). Basically, "Everything is true except > > false". And nil. You get to the point though - what makes zero > > so special that it would warrant being false? > > Because in the real world, zero means false. > > Suppose you have zero quarts of milk in your refrigerator. I am visiting and > I ask: > > Got milk? > > What's your answer, yes or no? > > No, of course. > > It's fairly unlikely that you would say, "Yes, I've got milk. I have zero > quarts of milk. There's nothing special about the number zero; it's just > like any other number. So, I've got milk." > > Is there any real-life situation where an answer like that would make the > slightest bit of sense? People would think you were either trying to annoy > them or had lost your grip on reality. > > That's why Ruby's interpretation of zero as "true" seems extremely peculiar > to me. There's a geeky kind of logic to it, but it doesn't map onto the real > world at all. milk_bottles = nil until milkBottles milk_bottles = fridge.try_to_figure_number_of_milk_bottles end puts "Finally found #{milk_bottles} milk bottels in the fridge." while ( value = some_number_data_source_stream.read ) puts "Current value: #{value}" end These are the kinds of situations where you want 0 to be treated as 'true'. > p.s. Don't get me wrong, I *like* Ruby. :-) But, it has its warts just like > every programming language. True. And in this case it's especially true for people coming from perl. Regards robert