Hacker News new | ask | show | jobs
by jfoutz 1037 days ago
It’s something else. Monkey patching comes from Ruby, since classes are open, you can change implementations at runtime. I’m not quite as familiar with meta magic, but I believe it has similar characteristics. Sorta like dynamically injected accessors via autoload in perl.

There are cool tricks, but they come at a cost. Both for the reader of code, and the compiler of code.

2 comments

> Monkey patching comes from Ruby

My Lisp Machine's operating system (MIT, end 70s onwards) is written in an object-oriented Lisp (using Flavors and later CLOS). Everything is open and everything can be changed at runtime. Mixins and similar stuff comes from there.

https://en.wikipedia.org/wiki/Flavors_(programming_language)

I'm happy to give lisp credit for everything cool.

but Common Lisp has all the good stuff you need to manage different generations of objects under changing classes, not the least of which is jumping into the running system and examining the running state. warnings and errors about redefinition, maybe jump under a different package to manage generations. state and functions are separate, thanks to dynamic dispatch.

Ruby, on the other hand, rewrites the class. hope all the data and functions are forwards and backwards compatible! good luck.

> Monkey patching comes from Ruby, since classes are open, you can change implementations at runtime.

Monkey patching is a feature common to many languages including Python, it did not originate in Ruby.

If I was having a punt I'd say it probably originates in Smalltalk or Lisp.

> Apparently from earlier guerilla patch (“code that sneakily changes other code”), understood as gorilla patch. A monkey patch was then a more carefully written instance of such a patch.[1] Or simply derived from monkey (“to mess with”, verb).

Wiktionnary

Certainly not in Lisp; I have never heard it before; I thought Op made it up :); but have looked it up on Wikipedia and indeed is a term. Seems just to alter the behavior at the runtime.