Monkey Patching in Go
bouk.co
bouk.co
I've always wanted a way to monkey-patch otherwise statically and well-bound code, but only for testing. In C, it's fairly easy to set up preprocessor rules to do so, though also litters your primary code with test specific stuff. I have mostly focused on how to integrate this into compiler logic; Building some functionality to replace specified symbols in the build phase. Simply replacing the function pointers in the runtime is brilliant, if more than a little hacky and prone to problems.
I look forward to playing around with this.
Monkey patching is a less invasive version of hooking used in dynamic languages. Bottom line: if you are dealing with assembly it's no longer monkey patching :-)
It kind fits in with what Wikipedia describes as monkey patching http://en.wikipedia.org/wiki/Monkey_patch
Definitely nice work!
This does have an unfortunate side effect though. Because Objective-C is a) compiled directly to machine code b) has no way of marking methods final and c) supports monkey patching, essentially no methods can be inlined by the compiler.
Eg.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Ho...
https://api.drupal.org/api/drupal/includes%21module.inc/grou...
https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...
Monkey patching ends and hooking begins when you go outside of what's provided by the language digging into assembly and byte code.
As soon as we can do this with Golang the orms we use will get much faster.
The patch is 12 bytes