On Thursday 30 January 2014 02:14 PM, Ronald Oussoren wrote:
On 24 Jan 2014, at 08:54, Suresh V.
wrote: On Friday 24 January 2014 10:39 AM, Ethan Furman wrote:
On 01/23/2014 08:09 PM, Suresh V. wrote:
Also it would mean that the client code imports from this package. I would like client code to remain exactly as it is (continue to import from its original package) but the behavior is enhanced once this package is imported on startup.
/Something/ has to adjust the pre and post conditions -- if not the client code, then what?
pre and post conditions are just one possible use of this.
Going back to my smtplib.SMTP.sendmail example. No changes in bulk of client code. Single patch module imported in main.
Why is this a good thing? You seem to propose adding a mechanism that makes it easily possible to modify the behaviour of existing functions, which makes it harder to reason about code.
It is a "good thing" because it adheres to the "Open/Closed principle" better than monkey patching does. Meaning open to extension and closed to modification.
While this is also possible without language changes with the current monkey patching mechanisms its at least clear that your doing something naughty when writing the patching code :-)
This if for those non-naughty times :-)