From: "Hal E. Fulton" Date: 2002-09-11T03:54:33+09:00 Subject: Re: Larry Wall's comments on Ruby ----- Original Message ----- From: "nico" To: "ruby-talk ML" Sent: Tuesday, September 10, 2002 9:31 AM Subject: Re: Larry Wall's comments on Ruby > On September 10, 2002 04:38 am, Gavin Sinclair wrote: > > > I'm not convinced that it's unnatural. We don't know the types of a and > > b, and for some objects a and b, a + b != b + a. > > > > I'm interested what you think the alternative is, or an argument against > > the above, and how you would like to see a + b defined in Ruby. > > > > Gavin > > I find that highly unnatural because we've been learning since grade school > that a + b = b + a. > > If the objects don't satisfy that property they should be using a different > symbol. True, but only up to a point. There's a boundary between mathematics and programming languages, and this pushes the boundary. First of all, even "=" doesn't mean in Ruby what we learned in grade school. This makes sense in Ruby (as an imperative): x = x + 1 but in math, it's just a false statement or an equation with no solution. Also, math doesn't distinguish between integers and reals in the same way. (Yes, it DOES have the concept, but it's not the same as in Ruby.) A Float in Ruby is a finite subset of the rational numbers which are an infinite subset of the real numbers. In math, if I say 5 + 3.2, I don't worry that the numbers are different "types." I mentally promote the 5 to 5.0 and go on and get 8.2. But in Ruby, these are actually different types (different classes). It's not *entirely* obvious what should happen. You *could* argue that an integer plus a float should "demote" the float: 5 + 3.2 yields 8. After all, aren't we used to this in division? We often make the useful definition that 10/3 yields an integer while 10/3.0 yields a float. Bottom line: The analogy between math and a programming notation is imperfect. Hal