News for hackers. Stuff that matters.
Re:Interface Upgrades in Go by thomasahle on Sunday December 07, 2014 @09:20PM (#8714583)
For all the comments Go gets on its typesystem, I suppose

    	if rt, ok := dst.(ReaderFrom); ok {
    		return rt.ReadFrom(src)
    	}
Isn't the most terrible way anyone has seen pattern matching implemented.

At least it is better than Java's instanceof + cast.

Re:Interface Upgrades in Go by zaphar on Sunday December 07, 2014 @10:19PM (#8714741)
For even more similar look to pattern matching look at Go's type switch.

    switch i.(type) {
        case OptionalInterface1:
           // do some extra thing we allow
        case OptionalInterface2:
           // do some other extra thing we allow
    }
It's really good when you have a set of mutually exclusive interfaces or types.
Re:Interface Upgrades in Go by jerf on Monday December 08, 2014 @09:16AM (#8716470)
You can do a passable impression of sum types that way too: http://www.jerf.org/iri/post/2917
Re:Interface Upgrades in Go by arnehormann on Monday December 08, 2014 @02:03AM (#8715326)
You should use switch v := i.(type) so you can access v as the type in a case.
Re:Interface Upgrades in Go by benjiweber on Monday December 08, 2014 @04:08AM (#8715585)
Re:Interface Upgrades in Go by danieldk on Monday December 08, 2014 @03:49AM (#8715544)
At least it is better than Java's instanceof + cast.

Except that in a language with generics you have to cast far less, so it is no surprise that Java is less optimized for type casting.

(The primary exception being the equals(Object) method, which most classes should have.)

Re:Interface Upgrades in Go by thomasahle on Monday December 08, 2014 @05:48PM (#8719747)
I'm not sure I see how generics help at this particular problem. Functional languages have advanced type systems, but still use pattern matching all the time.
Re:Interface Upgrades in Go by skybrian on Sunday December 07, 2014 @10:04PM (#8714703)
It certainly looks weird at first, but is there anything objectively wrong with it?