Hi --

On Mon, 9 Jan 2006, Steve Litt wrote:

> On Sunday 08 January 2006 05:04 pm, Gregory Brown wrote:
>> On 1/8/06, Steve Litt <slitt / earthlink.net> wrote:
>>> That's why I'm glad my electric stove has
>>> lights saying which burners are still hot. And that's why I enjoy
>>> programming in languages like Ruby, Python and Java, that protect me from
>>> myself.
>>
>> Java:  Yes. (in the average scenario)
>> Python:  Pretty much kinda maybe.
>> Ruby: You'll shoot your eye out!  ;)
>
> Everyone says that, but I don't see it (til it hits me in the eye? :-).
>
> Maybe I'm just used to C, where the slightest mistake leads to a subtle bug
> that happens every couple weeks.
>
> Sure, if I went out of my way I could make Ruby do corruptable things, whereas
> with C I cannot avoid it.
>
> Ruby has beautiful encapsulation. Yeah it could be defeated, but you'd really
> have to try. I want my language to protect me from my own mistakes, not from
> my own death wish.
>
> Personally, I'd NEVER gratuitously add a method or instance var to a class at
> runtime. If I needed more methods than the class provided, I'd subclass it. I
> mean, how hard is it to subclass something, especially in Ruby. Adding
> methods and instance variables to classes in real time reminds me of senators
> who add a social security amendment to a defense bill -- it's just bad
> business that can lead to no good.

I'm not sure what you mean by adding an instance variable to a class,
but as for methods, they're all defined at runtime.

   class C
     def m
     end
   end

That code gets executed, and then there's a class called C with an
instance method m.

I'm not sure what it is that you consider subclassing to be a better
choice than.  Are you talking about define_method?  Or the practice of
reopening core classes?


David

-- 
David A. Black
dblack / wobblini.net

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black