Where to put code for extending a class?

A

Avdi Grimm

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(TM) 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: http://avdi.org/devblog/
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com
 
J

James Britt

Phillip said:
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.
 
J

James Britt

David said:
Not by everyone :) I know I'm in the minority, but I'll put in a word
for those of us who dislike and, at least in my case, do not (and
never will) use the term "monkeypatching". It seems to me to do a very
bad job of conveying what's actually happening, which is neither
patching, in any sense that I've ever heard the term used, nor
"monkeying" (i.e., monkeying with the code, or monkeying around). All
"monkey" connotations are negative, and the issue of whether or not
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.
 
P

Phillip Gawlowski

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

James Britt wrote:
| Phillip Gawlowski 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 Gawlowski
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-----
 
D

David A. Black

Hi --

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

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See http://www.rubypal.com for details and updates!
 
R

Robert Dober

Hi --


On Thu, 8 May 2008, Robert Dober wrote:
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.
I see some ignorance of subtle semantics from part of a non native
speaker, thx for dotting the Ts and crossing the Is ;)
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.
 
D

David A. Black

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

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See http://www.rubypal.com for details and updates!
 
R

Robert Dober

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
 
R

Robert Dober

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 :)

R.
 
D

David A. Black

Hi --

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 :)

So is not looking for trouble :) 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

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See http://www.rubypal.com for details and updates!
 
R

Robert Dober

So is not looking for trouble :)
ooops I meant something completely different :)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,204
Messages
2,571,065
Members
47,672
Latest member
svaraho

Latest Threads

Top