On Sun, 7 Mar 2004, Mark Hubbart wrote:

> 
> On Mar 6, 2004, at 11:54 AM, Charles Comstock wrote:
> 
> >
> >> Please don't redefine a Kernel method. I think that's a Bad Idea(tm). 
> >> Why not use #random instead?
> >
> > Why is redefining a kernel method to take a different class of 
> > argument a bad idea?  It's not like it changes existing functionality, 
> > even if you had aliased it to take a range yourself, since your alias 
> > would take effect before it hit the underlying version.  I don't 
> > understand why this is considered so bad.  It hurts in static typed 
> > languages sure, but with duck typing this doesn't hurt us.
> 
> It's not redefining rand to take more varied arguments that's a bad 
> thing, it's defining it for Array#rand that's a Bad Idea(tm), IMHO. 
> Kernel is included in Object so that you can access it's methods easily 
> within other objects. Redefining it in a subclass could potentially 
> break lots of code. For example, I often do this:
> 
>    class Array
>      def randomize()
>        sort{rand(2)-0.5}
>      end
>    end
> 
> ... and defining an Array#rand would break this.

You must not be very fond of IO#gets, Thread#exit, Dir::open, or
Proc#binding :-)  Which is to say -- there are cases where Kernel
methods we use without a receiver do get redefined for specialized
purposes.  However, while it's moot anyway because of my fatal
Enumerable#size flaw, my snippet was really just to show the behavior
we were discussing on IRC.  No endorsement of reckless endangerment of
Kernel intended :-)

> I like the idea of allowing Kernel.rand(range), for reasons already 
> presented by others. Kernel.rand(array) seems a little iffy to me, but 
> that's me. :)

I agree; rand(range) seems reasonable but beyond that it starts to
feel wrong.


David

-- 
David A. Black
dblack / wobblini.net