On Tue, Feb 26, 2008 at 11:55 PM, James B. [email protected]
wrote:
That’s ridiculous.
“#{@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.
James, Sometime ago Rick O. 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.
From my own experience I have encountered similar problems countless
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?
Oh well, I’ll be extra brief this time, but