Live data from Hacker News

The Point of Pattern Matching in Scala (2009)

artima.com

1–3 of 3 posts

Re: The Point of Pattern Matching in Scala (2009)

#3

> with modern VM technology it's (pattern visitor) way more innefficient than pattern matching Can someone explain that bit? Visitor pattern is 2 virtual calls. That should be very efficient. How pattern matching is more efficient?

2 virtual calls are required to simply get Visitor's logic executed. But if you want your Visitor to actually do something usefull with visited object then you have to call a bunch of getters to extract the object data. This adds several more virtual calls. Pattern matching in Scala can be implemented as "messing with the bytecode", bypassing getters completely, which saves you all those virtual calls to them.