Where to put code for extending a class?

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

···

On Thu, 8 May 2008, Robert Dober wrote:

On Wed, May 7, 2008 at 3:06 PM, Brian Marick <marick@visibleworkings.com> wrote:

--
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!

What is the recommended place to put the code?

Personally I think it would be nice is if all extensions of standard
ruby classes etc.. would go into a special .rb file.

This way people all can look at what is changed (IF they are interested)
quickly.
Not sure what name would be a common ground, "core_extensions.rb" or
"extensions.rb" or ... I dont know. But having it in one file is, I
think, better in the long run.

···

--
Posted via http://www.ruby-forum.com/\.

Mike Stok wrote:

I am a little confused, and maybe my understanding of Ruby classes is
muddled:

If classes are never closed then why do the need to be (re-)opened?

The intention is to make clear that the functionality was added after
the initial creator considered the original implementation complete (for
varying degrees of 'complete'. It also carries the information that it
was done outside of the original implementation.

  'I added to NSNotification'

This could be taken as a patch to NSNotification's original source code.

Using 'reopening' implies that it is done during runtime, rather than
during design-time (as murky as *that* is with Ruby).

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

~ "My ethicator machine must've had a built-in moral compromise
~ spectral release phantasmatron! I'm a genius!" --- Calvin

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.

Hi --

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 :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 Wed, May 7, 2008 at 9:05 PM, David A. Black <dblack@rubypal.com> wrote:

On Thu, 8 May 2008, Robert Dober wrote:

Perhaps if you don't like the term monkeypatching, you'd prefer ninjapatching.

No connotations of bad code, or screwing around! And it gets the idea across.
--Kyle

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 Thu, 8 May 2008, Robert Dober wrote:

On Wed, May 7, 2008 at 9:05 PM, David A. Black <dblack@rubypal.com> wrote:

Hi --

On Thu, 8 May 2008, Robert Dober wrote:

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...

--
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!

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/

···

On Wed, May 7, 2008 at 11:16 AM, Kyle Schmitt <kyleaschmitt@gmail.com> wrote:

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

--
Avdi

Home: http://avdi.org
Developer Blog: http://avdi.org/devblog/
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

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 Thu, May 8, 2008 at 1:55 AM, David A. Black <dblack@rubypal.com> 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.

Hi --

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:

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, 8 May 2008, Robert Dober wrote:

On Thu, May 8, 2008 at 1:55 AM, David A. Black <dblack@rubypal.com> wrote:

--
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!

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

···

On Thu, May 8, 2008 at 2:34 AM, David A. Black <dblack@rubypal.com> wrote:

Hi --

So is not looking for trouble :slight_smile: