Open grosser opened 13 years ago
I disagree. While I do agree with you that using an exclamation mark is far from perfect, I do not like your alternative, both from a technical and a design standpoint. The basic assumption it violates: You should never leak "patched" objects to code that is not yours.
Unfortunately, object proxies only work well up to a certain point. Especially for those objects wrapped, like integers and strings. It might break for instance if you hand them to a C extension, or if you hand it to code that does type assumptions.
Even if that wouldn't cause issues, it would be a huge performance hit. You practically disable any kind of method table caches or call site caches for delegated methods and have a double dispatch.
In the API offered by "patched" objects we can be highly opinionated, even potentially override methods. If we now start leaking those objects, than what's the point? We could just go for monkey-patching instead. Think of it as being DIY refinements.
hmm good point, maybe another syntax like method_ could solve the conflict
Have to think about that, not sure if I like it.
'patched' objects should just behave like normal objects, so its not necessary to unpatch them all the time, but if needed a simple .unpatch should do it, leaving the ! free for the noral ! meaning (modify object)
Unpatched['xxx'].foo.bar.unpatched