Monday May 14, 2007
Joseph D. Darcy's Sun WeblogJoseph D. Darcy's Sun Weblog Closures, Visitors, and Hedgehogs It has been said that there are foxes and there are hedgehogs and "the fox knows many tricks, but the hedgehog knows one great trick." The one great trick of computer science is adding a level of indirection in the right place. There is an interesting similarity between the level of indirection added by the visitor pattern and by closures.
The
visitor pattern
when used on a type hierarchy allows arbitrary operations to be added
independently by third parties after the hierarchy is made, at the
upfront cost of an With both visitors and closures, the construct may be unfamiliar when first seen, but the utility of these patterns make them well worth learning. The extensibility afforded by visitors and closures creates much more scalable environments by allowing functionality to be added without the need for coordination from a single authority, either the type hierarchy or language maintainer. (2007-05-14 08:03:35.0) Permalink Comments [6]Post a Comment: Comments are closed for this entry. |
Calendar
RSS Feeds
All /Annotation Processing /General /Java /JavaOne /Numerics /OpenJDK SearchLinks
NavigationReferersToday's Page Hits: 260 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Posted by Ricky Clarkson on May 14, 2007 at 08:54 AM PDT #
Posted by Joe Darcy on May 14, 2007 at 09:17 AM PDT #
Posted by Rémi Forax on May 14, 2007 at 11:38 AM PDT #
Posted by Joe Darcy on May 14, 2007 at 05:27 PM PDT #
I was not aware that philip wadler wrote something on these problems. I created a small package that use byte-code generation to solve these problems.
About invokedynamic, i hope to generate a bytecode that use it in a similar way java.lang.Proxy does, so it can be accessed from Java but in a safe way.
About JSR269 vistors, i have done something very similar in Tatoo, a parser generator and i wonder why JSR269 visitor doesn't use a type variable for exception, is there a reason ?
Rémi
Posted by Rémi Forax on May 17, 2007 at 05:45 AM PDT #
Rémi,
Wadler coined the term "expression problem" for this issue; he was proud of the dual meaning :-) For JSR 269, we looked an other approaches to addressing the expression problem with generics, but found they added too much complexity without helping the code migration issues.
We did consider how many type parameters the JSR 269 visitors should have. We felt one parameter for a return type was a substantial improvement over no type parameters, a second type parameter for the argument was a much smaller improvement, and a third parameter for exceptions added too much awkwardness for much too small an improvement in expressiveness for an uncommonly needed feature. The GJ paper also recommends two type parameters for visitors while noting a third for exceptions is possible.
Posted by Joe Darcy on May 17, 2007 at 11:32 AM PDT #