python difference between dispatch and monkey patch

What is the difference between dispatch and monkey patch?

Monkey patching is explained a bit here. numpy uses dispatch. A comparison with an example would be good, if there is a difference at all.

Upvotes: 1

Views: 212

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 149125

Monkey patching is about adding functions at run time to a class or object. Dispatching is about calling methods discovered at run-time on an object that already implements them. Monkey patching is common in dynamic languages like Python or Ruby and would be a pain in more static languages like C, Java or C++. But dispatching is (rather) easy to implement in static languages. The reason why it is used in numpy which internally uses C functions.

Upvotes: 1

Related Questions