Where to put code for extending a class?

Phillip G. wrote:

negative connotations. Reopening a class shouldn’t be done lightly!)
It’s a useful distinction.


James B.

http://www.rubyaz.org - Hacking in the Desert
http://www.jamesbritt.com - Playing with Better Toys

David A. Black wrote:

its a good idea to modify existing classes in any given case is a lot
more complicated.

I’m with David.

I can sort of understand the use of the term as the variant of Guerrilla
Patching, but increasingly it gets used to mean almost any sort of
run-time code alteration. I.e. it’s becoming more noise than signal.


James B.

http://www.rubyaz.org - Hacking in the Desert
http://www.jamesbritt.com - Playing with Better Toys

On Wed, May 7, 2008 at 11:16 AM, Kyle S. [email protected]
wrote:

Perhaps if you don’t like the term monkeypatching, you’d prefer ninjapatching.
http://avdi.org/devblog/2008/04/01/announcing-ninja-patching/

Hey now, let’s not start diluting the Ninja Patching™ brand.
Monkey patching is for sissies who are content merely to make a
maintenance programmer spend half a day, tops, tearing their hair out.
Ninja Patches are a whole new level of silent code assasination.

This one time a Ninja flipped out and killed a whole town[1] just
because someone called his code a monkey patch. So I’d tread
carefully if I were you.

If you still don’t understand I suggest you just ask a Ninja[2].
He’ll explain the difference very clearly… to your corpse.

[1] http://www.realultimatepower.net/
[2] http://askaninja.com/


Avdi

Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

James B. wrote:
| Phillip G. wrote:
|>
|> While I’m not David, nor do I play him (or any David) on TV, here’s my
|> two cents:
|>
|> ‘I reopened NSNotification and added/defined [] for use.’
|>
|> Short, sweet, to the point, and neutral in its connotation.
|>
|>
|> (I admit that I chose ‘monkeypatching’ earlier to actually invoke the
|> negative connotations. Reopening a class shouldn’t be done lightly!)
|
| It’s a useful distinction.

Most of the time, I use ‘reopen’ when talking about this sort of issue.

However, using somewhat drastic measures can get the point across that
it is not to be done lightly.

To abuse a Spideman quote: With great power comes great responsibility.

And reopening a class should be a last resort, not the standard modus
operandi, IMHO.


Phillip G.
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com

~ - You know you’ve been hacking too long when…
…you pick up a rootbeer and read the label as “High Res”, not Hires.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgh8HEACgkQbtAgaoJTgL+roQCfQfun+yAnIvRuI7riweCVmj6S
yzsAoIOCrVqpgTT7v7WGVlFmgYJ6cdfb
=VKuc
-----END PGP SIGNATURE-----

Hi –

On Thu, 8 May 2008, Robert D. wrote:

On Wed, May 7, 2008 at 3:06 PM, Brian M. [email protected] wrote:
Well David at first I wanted to disagree with you, because it is just
such a nice word ;), you see MP is quite ambiguous in the UK ;), but I
guess you have some reason to be against the word.
I cannot share the negative feeling with the word monkey, after all we
are close relatives, but I guess the most important question is the
following, and I am asking the teacher here:

I don’t dislike the word monkey (and of course none of this has to do
with actual monkeys) but it occurs typically in phrases like
“monkeying around” and “monkey business” and “monkeying with”, all of
which have to do with meddling, incompetent, ill-advised behaviors.
“Monkeypatching” was coined specifically to convey these kinds of
connotations. I’ve heard people argue that it no longer does, because
“we” (as opposed to “them”) think “monkeypatching” is not bad. I don’t
think modifying existing classes is inherently good or bad, and I
don’t like reducing the issues involved to a kind of up-or-down vote
based on whether or not one thinks the word “monkeypatching” is
negative.

Do you have the experience that the expression MP is confusing for beginners?

I don’t know, because I’ve never used the term “monkeypatching” except
in discussions of the term itself, and it’s never come up in a class.

David

On Thu, 8 May 2008, Robert D. wrote:

I don’t know, because I’ve never used the term “monkeypatching” except
in discussions of the term itself, and it’s never come up in a class.
Interesting…

I should say: the word “monkeypatching” has never come up. The topic
of adding functionality to existing class and objects comes up a lot,
of course.

David

On Wed, May 7, 2008 at 9:05 PM, David A. Black [email protected]
wrote:

Hi –

On Thu, 8 May 2008, Robert D. wrote:

negative.
I see some ignorance of subtle semantics from part of a non native
speaker, thx for dotting the Ts and crossing the Is :wink:

Do you have the experience that the expression MP is confusing for
beginners?

I don’t know, because I’ve never used the term “monkeypatching” except
in discussions of the term itself, and it’s never come up in a class.
Interesting…

thx David
R.

On Thu, May 8, 2008 at 1:55 AM, David A. Black [email protected]
wrote:

I should say: the word “monkeypatching” has never come up. The topic
of adding functionality to existing class and objects comes up a lot,
of course.
Understood, I meant “interesting” in the sense that I was kind of
pretty sure that you had some didactic ideas about it - and I guess
you still have, right? - but anticipating a problem that has not yet
arrived is a big quality :slight_smile:

R.

On Wed, May 7, 2008 at 7:57 PM, James B. [email protected]
wrote:

David A. Black wrote:

I’m with David.

I understand David’s POV as well as Philip’s, I would have said MP as
did Philip, whome I want to thank for the explanation of my short
answer when I got cut off by some work.
That is why I asked David if MP was a well known term for nubies, it
does not seem to be so.

However James, David did specifically say that he did not judge the
technique by disliking its name. For what I am concerned I think MP or
Core Class Reopening is like most other techniques, when used with
care it is a marvelous thing.

OP’s usecase was a good one IMHO very consistent with String in
general, I believe that we shall judge techniques by the semantic use
we are making of them.

class String
def cap_all_words … end
end

does seem much better than things like

class MyClass < String
def capitalize; #do cap_all_words here; end
end

I can sort of understand the use of the term as the variant of Guerrilla
Patching, but increasingly it gets used to mean almost any sort of run-time
code alteration. I.e. it’s becoming more noise than signal.

What do you mean with code alteration here? I feel quite lost, seems
plain vanilla programming to me.
Maybe there are issues with reopening core classes ( can we call it
RCC ?) in libraries but for an application it often is the simplest
thing that works, and that is a big quality of code.

Just my 0.02c

Robert

http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Hi –

On Thu, 8 May 2008, Robert D. wrote:

arrived is a big quality :slight_smile:
So is not looking for trouble :slight_smile: Believe me, there’s plenty to do in
these courses without a lecture from me on the term “monkeypatching”.
Come to think of it, I think it has come up once or twice, because
someone in the class has heard the term and asks about it, and we just
chat about it and I say what I think and the students are free to do
with it whatever they end up deciding to do.

David

On Thu, May 8, 2008 at 2:34 AM, David A. Black [email protected]
wrote:

Hi –

So is not looking for trouble :slight_smile:
ooops I meant something completely different :slight_smile:
I meant simply: Of course you do not need necessarily to have a
problem in class with the term MP to think about the negative
implications of the term in class and of course elsewhere. Sorry David
I got caught in the “classroom setup” for some personal reasons my
brain is thinking a lot about teaching right now. I realize that this
reduced the thread a little bit, thx for your friendly replies.

Robert