3 ms·
In this case it doesn't even seem fair to say expressiveness would be sacrificed, because expressiveness is just as much about human comprehension as it is abou
by dasil003 16y ago
In this case it doesn't even seem fair to say expressiveness would be sacrificed, because expressiveness is just as much about human comprehension as it is about powerful code modification. In the current implementation there are too many ways for refinements to leak out of their defined context, granted it could be argued that this makes refinements more powerful, but it also undermines their very purpose (ie. isolating code).
I'm not a Ruby internals expert, but I've done my fair share of meta programming and debugging of monkey-patch conflicts. A more static version of refinements will give 99% of the benefit while avoiding most of the landmines Charles is describing. The other 1% can probably be served by adopting some other technique rather than looking to refinements. Ruby is already such a dynamic and powerful language that it seems silly to say that refinements need to have this uber-flexibility. All they need to be able to do is isolate monkey patches within a library and they've already provided a huge practical benefit. Being able to inject refinements into someone else's code? That's just not very important, and if it is for some particular case there are other techniques Ruby affords you, all of which should be used cautiously.
Barring some flaw in Charles' analysis, I'd say it's a no brainer that refinements need to go back to the drawing board.