James, Sometime ago Rick Olson wrote this:
http://weblog.techno-weenie.net/2007/12/19/adventures-in-rails-debugging
Does ring a bell, doesn't it? All the libraries Rick mentions in his
blog are well regarded and yet he has a problem.
times and you know these problems are HARD to debug.
As i wrote earlier, today you have access to source code of all the
libraries you are using because Ruby is source based interpreter and
you can still debug problems because of accidental overrides or
modifying core classes by looking at source code, but what if Rubinius
or IronRuby becomes defacto and people started distributing compiled
bytecodes?
I propose a small change in the language and perhaps I know it won't
see light of the day, but how about this?
class Array
def to_csv #> works if in final program no one is actually doing the same
end
end
However, suppose you use another library and they have done the same,
that code won't run and Ruby will throw up and that sorta makes
sense.However, if you are sure of what you are doing, you can go ahead
and write:
class Array
def! to_csv #=> similar to override keyword in other languages
end
end
Ditto, if you want to override methods defined in other classes, you
must use "def!" .
I know this is somewhat impractical because Ruby has grown into such a
beast, lots of standard library classes and gems will need small
modification ( but we are in midst of such modification anyways
courtesy of 1.9.x ).
My point is, I love open classes, but it shouldn't hurt to have little
bit of safety precaution built into the language, does it?
···
On Tue, Feb 26, 2008 at 11:55 PM, James Britt <james.britt@gmail.com> wrote:
Trans wrote:
>
> On Feb 26, 10:45 am, "Jones, Brian - McClatchy Interactive" > > <bjo...@mcclatchyinteractive.com> wrote:
>> I'd be at least a little interested in potentially offering developers
>> the chance to 'lock' their classes from monkey patches. This could be
>> useful to the 'core' library that comes with Ruby, and to at least make
>> developers look at extension points provided via an actual API instead
>> of just immediately jumping on monkey patching for solving all problems.
>
> That's ridiculous.Fears about open classes sound very much like what people say about
dynamic typing."#{@core_feature} is unpredictable!"
"#{@core_feature} creates problems that cannot be found until run-time!"
"#{@core_feature} is unsafe!"
"#{@core_feature} should be locked down!"
It's not that these claims are entirely untrue, it's just that, in real
life, most people simply do not encounter the alleged problems.Code that is poorly written or does not play well with others tends to
get discarded.
From my own experience I have encountered similar problems countless