Florian Gilcher
5/16/2008 7:49:00 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On May 16, 2008, at 9:31 PM, Robert Dober wrote:
> On Fri, May 16, 2008 at 8:58 PM, Phillip Gawlowski
> <cmdjackryan@googlemail.com> wrote:
>
>> Yes and no. Monkey patching it is called, if one ignores potential
>> side
>> effects, or performs something dangerous, like re-opening a a Core
>> class.
>>
> Sorry Philip to disagree slightly, re-opening a Core class is not
> dangerous it is potentially dangerous.
> I would it call dangerous in libraries not applications and still
> there are libraries specifically made to do this as e.g. Facets.
> Ok as OP is a nuby maybe we might say dangerous after all, but not
> tabou at least ;).
>> | How would you call this style of programming? I'm asking because
>> I'm
>> | quite new to Ruby and currently trying to learn the right
>> vocabulary to
>> | easily communicate with other Ruby programmers. I am definitely not
>> | looking for flame war!
> Hey if you were looking for a flame war, this is not the best place
> anyway ;), no worries your question is a sensitive one!
>>
>> Probably 'dynamic'. :P
> Absolutely agree here
>>
> Robert
> --
Actually, I disagree with both definitions. I don't consider opening
and extending
Classes (be they core or not) monkey-patching.
I define monkey-patching as "opening and changing behaviour of a
method/class
in the knowledge that other classes/libraries depend on it".
So
class Array
def my_funky_function
"this array is of the hook"
end
end
has nothing to do with monkey-patching - chances are high that there
are no conflicts.
class Array
def []=(elem)
#whoops, i dropped the element
end
end
is a total different case. I postulate that most Programs written in
Ruby depend on the behaviour
of Array#[]=. So this is monkey-patching at its worst. (you patch a
certain functionality because
you think that it should behave differently. In this case, it is
pretty obvious, that this try was a failure.
The wikipedia has a nice explanation:
"In Python, the term monkey patch only refers to dynamic modifications
of a class at runtime based on the intent to patch existing methods in
an external class as a workaround to a bug or feature which does not
act as you desire. Other forms of modifying a class at runtime have
different names, based on their different intents. For example, in
Zope and Plone, security patches are often delivered using dynamic
class modification, but they are called hot fixes.
In Ruby, the term monkey patch was misunderstood to mean any dynamic
modification to a class and is often used as a synonym for dynamically
modifying any class at runtime."
Regards
Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEARECAAYFAkgt5QoACgkQJA/zY0IIRZbRWQCdG0vRaJ4pNCCVTQsa2lgKbs0B
cy0AnjlxblREs1mQhmqn6WEkPP/HjEqr
=fQOe
-----END PGP SIGNATURE-----