DMD 0.148 release

Deewiant deewiant.doesnotlike.spam at gmail.com
Mon Feb 27 08:23:44 PST 2006


Ivan Senji wrote:
> Deewiant wrote:
>> Ivan Senji wrote:
>>
>>> One more thing. I heared from a Ruby user that in Ruby 0 means true.
>>
>>
>> To clarify, since that makes it sound a bit too much like "...and 1 means
>> false": in Ruby the only two things that are false are, of course,
>> false itself,
>> and nil, which is similar to D's null. 0, like all other numbers, is
>> true.
> 
> Thanks for the clarification. It is really interesting how Ruby takes a
> completly different approach. Not that I agree with it. Strange and
> arbitrary decision IMO to make all numbers true. Why not make all
> numbers false?
> 

Probably because of Ruby's TIMTOWTDI approach - There Is More Than One Way To Do
It. Thus, it tries to cater to programmers of all languages - including C, and
so if you liked to write "while (1)" before you can still write "while (1)". You
can also write "loop do", "for (;;)", "while (true)", and probably do the same
thing in at least a dozen other ways.

Point being that Ruby has no reason - and it might even be against its idioms -
to take so clearly a deviant approach to true and false as to declare numbers
false, when in most languages people nowadays use everything apart from 0 is true.

Why, then, 0 is true, I cannot say; probably because all other numbers are true,
and 0 has no need to be an exception. It might be true in other languages
because they are strongly typed (or at least somewhat strongly - C isn't that
strongly typed, and even in D pointer arithmetic can do quite a bit to break the
type system, AFAIK), and a "false" value is very handy for a function that
returns an integer. In Ruby, you can just return false or nil, whichever is
appropriate, on error, even if the method in question normally returns an integer.



More information about the Digitalmars-d-announce mailing list