On Fri, Sep 5, 2014 at 1:07 PM, Nick Wellnhofer (JIRA) <[email protected]> wrote:

> Nick Wellnhofer commented on CLOWNFISH-12:
> ------------------------------------------
>
> Another approach are "implicit" interfaces like in Go.

A couple more comments about Go-style interfaces...

Go is quite deliberately designed to avoid inheritance; its type embedding is
syntactic sugar in support of composition.

    http://en.wikipedia.org/wiki/Composition_over_inheritance

In Go, if the type Hello has a Greet() method, embedding Hello within HelloJr
makes it possible to call Greet() on HelloJr, object, but **the method
reciever is the inner type**.

Those who are used to inheritance would expect the second line of output for
this program to be "wassup world":

    http://play.golang.org/p/nqO1UKbzP6

    hello world
    hello world

Here are the shenanigans you have to go through to make that happen (which are
definitely not idiomatic Go):

    http://play.golang.org/p/PihtxohvHa
    https://paste.apache.org/foJK
    http://tech.t9i.in/2014/01/inheritance-semantics-in-go/

I understand why the Go folks believe their type system is superior and hope
that it will propagate, but I'm not yet persuaded that Clownfish interfaces
should emulate this aspect of Go's interfaces.

On a related note, Go's lack of support for inheritance is problematic for
classes which are designed to have methods overridden:

    
http://lucy.apache.org/docs/perl/Lucy/Docs/Cookbook/CustomQueryParser.html#Extending-the-query-language

    To add support for trailing wildcards to our query language, we need to
    override expand_leaf() to accommodate PrefixQuery...

To support such functionality for Go, QueryParser would need to delegate to a
"LeafExpander" instead of calling Expand_Leaf() on itself.  To customize
behavior, one would create a QueryParser which has-a custom LeafExpander,
rather than creating a new subclass which is-a QueryParser yet overrides
Expand_Leaf().

Interestingly, such an approach would work for other host languages as well.
Composition seems to map cleanly to more host languages than inheritance.

Marvin Humphrey

Reply via email to