Anne van Kesteren

Monkey patch

There appears to be trend where specifications monkey patch a base specification. A monkey patch being a subtle change to an existing algorithm only observable if you have seen both the new and the base specification. Some examples: Custom Elements attempts to redefine the createElement() method; Resource Timing adds a hook into each fetching end-point within a document without actually defining this in any amount of detail; Content Security Policy hijacks JavaScript’s eval(). (Using dated TR/ URLs here as an exception so these examples remain useful going forward.)

Apparently it is not clear that this is bad design. We should avoid monkey patching (hereafter patching). It has at least these problems:

Note that it is fine to have extension points. Both adopting and cloning of nodes can be hooked into by other specifications (and soon JavaScript for Custom Elements). Explicit extension points make the model clear. If adopting was instead merely patched from HTML’s img element definition it would not be clear for someone reading the adopting algorithm that adopting is actually more involved.

If you encounter patching, please file a bug. If you are writing a specification and temporarily want to patch a base specification to help implementations along, file a bug on the base specification so the community is informed of what you are trying to do.