[Grace-core] Default methods

Kim Bruce kim at cs.pomona.edu
Sun Feb 8 15:58:26 PST 2015


Yes, this is another Java patch.  … and I agree that you are better off including all desired methods from the beginning.  I’m not sure it would work poorly with structural types as the default methods are only allowed to access public methods of the class/object.  However, it would certainly complicate the run-time.

I thought Andrew wanted to have something like “open classes/objects” so that methods could be added later to a class or object and all objects from libraries used could pick up that method as well.

If no one else is interested, then I’m happy to drop it as I would likely never use it..

This came up because I was reading about Java’s introduction of closures, and default methods are tangentially related (basically they wanted to add a “forEach” method to existing collection classes in a way that wouldn’t break existing code).

Interestingly, their closures can only access “essentially final” variables from the outer scope.  I assume this restriction has to do with the poor implementation rather than anything we need to worry about.

This all came up because I’m lecturing on iterators in Java tomorrow in our data structures class and trying to add up-to-date material.

Kim



> On Feb 8, 2015, at 3:38 PM, Andrew P. Black <black at cs.pdx.edu> wrote:
> 
> 
> On 8 Feb 2015, at 14:10, Kim Bruce <kim at cs.pomona.edu <mailto:kim at cs.pomona.edu>> wrote:
> 
>> Andrew,
>> 
>> Does something like Java 8’s default methods (methods added to a type rather than an implementation — and not allowed to refer to instance variables) satisfy your needs for extensible primitive types?
>> 
>> http://zeroturnaround.com/rebellabs/java-8-explained-default-methods/ <http://zeroturnaround.com/rebellabs/java-8-explained-default-methods/>
>> 
> 
> I see default methods as one more patch made to cover-up a bad design decision made in 1994. 
> 
> Like James said, I don’t see how they would work with implicit typing.  In Java, when you say that an object satisfies and interface, it gets the additional methods, which must (presumably) be implemented in terms of the remainder of the interface.  We never say explicitly that an object satisfies an interface.
> 
> I suppose that when Grace gets a “no-such-method” error on a receiver r, it could look at a list of default methods and see is there is one with the right name, and then see if its required methods are supplied by r — or by other dealt methods on r, recursively.   This seems really arcane.
> 
> The right thing is to simply give the receiver the right method in the first place.  And that’s pretty easy to do, I think.
> 
> 	Andrew
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20150208/0dacc081/attachment.html>


More information about the Grace-core mailing list