Leszek Dubiel wrote:
> I am looking for scripting language to replace Perl, which I am using
> now. I don't like Perl, because its awful syntax. I thought about
> Python when I've heard of Ruby. I study Ruby now, it seems to be
> excellend (everything is object) and I have one question.
> 
> Why do you have two classes of integers? I think there are only two
> solutions for numbers in a good language:
> 
> 1. Numbers can be as big as machine word. To use bigger ones module
> should be included.
> 
> 2. Nubers can be as big as programmer wants, but DON'T suply two
> classes for the same THING. There should be one class to rule them all
> -- when number is small it is just one word, when it gets bigger it is
> a list. 

.... which is kind of what FixNum and BigNum do under the hood. When the 
number is small (31 bits), it stays FixNum. When a resulting computation 
with a FixNum is too big, a BigNum is returned instead. You have no need 
to instantiate FixNums and BigNums explicitly.

I think the more correct thing to say for Ruby is that it supplies one 
TYPE (integers) that is implemented using two CLASSES (FixNum and 
BigNum) for efficiency.

> Programmer wants to use numbers and don't want to care about
> implementation. If this is so in Ruby, then using two classes is not
> good and that classes should be hidden to user (programmer).

Too much hiding is like training wheels and would turn the experts off. 
It is already pretty hidden in actual usage.

> If Ruby
> will have implemented BigNum, Fixnum, then to be complete it sould
> implement BigFload (huge precission),

require 'bigdecimal' # Check.

> Complex, 

require 'complex' # Check.

> Naturals....

Natural numbers are non-negative integers, so FixNum and BigNum cover 
them fairly well. Were you thinking of rational numbers perhaps or am I 
missing something obvious?


> I would like to be convinced that Ruby solution is good -- now I don't
> see any reason for having two classes and I feel that some time in the
> future this would be a problem. Good languages are good at the
> beginning, but after few years they are patched, and patched -- they
> are getting worse and worse. (For example "use strict" in perl -- it
> seems to me as a patch that prevents programmer from doing something
> wrong...)

The two classes are a good solution as far as it is transparent. You can 
add and multiply numbers, not having to worry about the boundary of a 
FixNum: If you break the boundary, results appear as BigNums, which 
although slower and more memory hungry, give the right answer.

-- 
(\[ Kent Dahl ]/)_    _~_    _____[ http://www.pvv.org/~kentda/ ]_____/~
  ))\_student_/((  \__d L b__/     Master of Science in Technology     )
( \__\_õüõß/__/ ) _)  Industrial economics and technology management (
  \____/_öß\____/ (____engineering.discipline_=_Computer::Technology___)