On 09/09/2014 04:04, Marvin Humphrey wrote:
However, we have a problem with C implementation code: how can we get the C
compiler to tell us whether invoking an interface method on a given value is
safe?

In Go, the compiler detects invalid assignment to an interface variable
(<http://play.golang.org/p/mT743SWoxu>):

     package main

     type Futzer interface {
         Futz()
     }

     func main() {
         var futzer Futzer = "I am not a Futzer" // fails to compile.
         futzer.Futz()
     }

In Clownfish-flavored C, we can perform a runtime check:

You can also perform a runtime check in Go 
(http://play.golang.org/p/8irDzxASe4):

    futzer, ok := any.(Futzer)
    if ok {
        futzer.Futz()
    } else {
        fmt.Println("Not a Futzer")
    }

I think we can make that check redundant using DSO-style lazy loading
techniques: have each class start off with a dummy interface table populated
with stubs which lazily build the interface table, replacing themselves and
reinvoking on success or throwing an exception on failure.

I can't see how this would work. The interfaces a class could implement aren't known at compile time.

Nick

Reply via email to