2

This question about how to extend a Scala collection led me to this answer, which extends from SetProxy rather than Set. But SetProxy has since been deprecated! The documentation says "(Since version 2.11.0) Proxying is deprecated due to lack of use and compiler-level support."

Why has proxying not gotten use and compiler support? Does Scala provide a better technique for accomplishing the same thing? Was it found to have some fatal flaw?

Community
  • 1
  • 1
Ben Kovitz
  • 4,920
  • 1
  • 22
  • 50

1 Answers1

4

Proxying is deprecated because it is fragile. A proxy is supposed to forward all calls back to some other implementation. But what if you add a new method to the Set hierarchy--will anyone remember to add it to SetProxy and make sure it points where it should?

In practice, there was no good way to verify that proxies were actually functioning correctly. So the decision was made that it's better to not have the functionality at all than to have something that looks like it works but actually doesn't any more. Compiler support for proxying might make it easy enough to maintain robust proxies, but the manual approach just isn't robust enough.

Rex Kerr
  • 166,841
  • 26
  • 322
  • 407
  • Yikes! I hadn't realized that the proxy classes were maintained manually. I figured they had to work by some clever forwarding mechanism. Does Scala provide some other way to accomplish what a proxy does, like what I'm asking [here](http://stackoverflow.com/questions/24301098)? Macros, maybe? – Ben Kovitz Jun 19 '14 at 18:02
  • 2
    Extending collections is not an easy thing to do. You probably want map on your new collection to return a collection of the same type, but for that you need `CanBuildFrom`s and possibly a `YourNewSetLike` in addition to your new class. Proxying would not be something a blackbox macro could help you with, but others might be able to. A compiler plugin is more the way to go, but the collections hierarchy uses more features than the compiler can reasonably be expected to sort through when trying to find an automatic solution. I'm not sure there's any great solution. – Rex Kerr Jun 19 '14 at 18:12