rkh / unpatched

Yet another WTF library!
http://rkh.github.com/unpatched/
MIT License
23 stars 0 forks source link

use unpatched method to unpach an object #1

Open grosser opened 13 years ago

grosser commented 13 years ago

'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

rkh commented 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.

Technical reasons

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.

Design reason

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.

grosser commented 13 years ago

hmm good point, maybe another syntax like method_ could solve the conflict

rkh commented 13 years ago

Have to think about that, not sure if I like it.