closures after all?

Lawrence Kesteloot lk at
Fri Nov 20 14:50:24 PST 2009


If I understand pattern-based specification, it's basically
compile-time duck typing (e.g., C++ templates). One advantage of
interface-based specifications is that there's a javadoc I can read to
learn about the contract. For example, I can read the javadoc of
Iterable to figure out how to design my class to be
foreach-compatible. From there I can find all implementing classes to
see how they did it. I'd rather not have to go back to the language
spec for that. AutoCloseable's description of what the close() method
must do is more convenient (hence will be read more often) than the
JLS's. There's power to giving something a name and not just a

I have a similar objection to closures: it encourages variables and
parameters that are anonymous function signatures with no javadoc to
help me learn about the contract. (CICE is exempt from this


On Fri, Nov 20, 2009 at 2:22 PM, Neal Gafter <neal at> wrote:
> On Fri, Nov 20, 2009 at 2:02 PM, Bob Lee <crazybob at> wrote:
>> I get it now. My fault. I still prefer the simpler interface-based
>> approach.
> I distinguish interface-based and pattern-based this way:  An
> interface-based specification accepts a value of a particular interface, and
> invokes methods defined on that interface.  That is how the for-each loop
> works.  A pattern-based specification is defined by source translation,
> invoking a method on whatever type results from the translation in each
> particular circumstance.
> While the current ARM specification requires that the object implement the
> AutoCloseable interface, it does not invoke the method from that interface.
> The requirement that the value be a subtype of AutoCloseable is not actually
> used by the specification.  For example, the specification still makes sense
> if AutoCloseable is defined with no methods, or if the requirement is simply
> removed from the specification.  The translation is defined in terms of
> invoking a method on the actual type of the object to be disposed, not the
> interface method on the interface type.  As far as I can tell, ARM is a
> pattern-based specification but with an additional requirement that the
> value be a subtype of AutoCloseable.
> What is the value of that part of the specification that requires the object
> be an instance of that particular interface?

More information about the coin-dev mailing list