DEV Community

Discussion on: Monkey patching: What is it and should you be using it?

Collapse
 
zevenberge profile image
Zevenberge

I've used this a few times. For my hobby projects, I use D. Its main dependency and build tool (dub) doesn't download pre-compiled libraries, but rather the source code, and builds the library from there. Which means that you can actually edit the dependent source and get your own version of the library. I've done it a few times, mainly to try to fix a bug or investigate suspicious behaviour.

In our production code base we ran into problems like that as well. Our solution was to copy the source for a bugged class into our own project and fix the bug locally. Fortunately, this was a top-level class which we were able to swap out rather painlessly. In a different project, we made our own fork of a library and changed its internals to our needs.

I think TBH that locally monkey pawing should be avoided. Projects should work 'out of the box' as much as possible to reduce errors and frustration, as you've mentioned. Also, as we found out, forking the code means that we were also responsible for the maintenance.

Collapse
 
napoleon039 profile image
Nihar Raote

Totally agree!