A Rust Contributor Tries Their Hand at Go
The problem with Go is that you don't grok Go interfaces.<p>EDIT: downvoters, please explain what's wrong with my comment.<p>Go interfaces are quite a novel concept, and most developers that jump from language X to Go don't have enough time and experience to understand how they work, and how to design their application around this new model.<p>Their example of the messaging system/UI application is a straight port of the Rust code, and they lament the fact they have to use interface{} to overcome the lack of object orientation or pattern matching.<p><pre><code>    func paintingLoop(ch chan interface{}) {
        // shorthand for a loop over receiving over
        // a channel
        for msg := range ch {
            switch ch.(type) {
                case Quit:
                    // quit
                case DrawLine:
                    // cast to a drawline message
                    line := msg.(DrawLine)
                    // draw `line`
                case DrawTriangle:
                    tri := msg.(DrawTriangle)
                    // ...
                case SetBackground:
                    bg := msg.(SetBackground)
                    // ...
                default:
                    // Need a default case in case
                    // some other type is fed through here.
            }
        }
    }
</code></pre>
This is not idiomatic Go. The author here should be leveraging Go interfaces and they wouldn't lose type safety.<p><pre><code>    type Drawable interface {
        Draw()
    }

    type Line struct {
        x1, x2, y1, y2 int
    }
    func (l *Line) Draw() { ... }

    type Circle struct {
        cx, cy, radius int
    }
    func (c *Circle) Draw() { ... }

    func paintingLoop(ch chan Drawable) {
        for object := range ch {
            object.Draw()
        }
    }

    func main() {
        ch := make(chan Drawable)
        go paintingLoop(ch)

        ch <- &Line{x1: 10, y1: 10, x2: 50, y2: 50}
        ch <- &Circle{cx: 10, cy: 10, radius: 20}
    }

</code></pre>
You wouldn't expect Python programmers to try Haskell over a weekend and have enough experience with it to write a blog post about "Thinks I dislike about Haskell", but it seems much to often people play with Go and, when they fail to translate their ideas to this new language, post yet another "rant" on HN about how Go sucks.<p>Go has its fair share of shortcomings, but try to _learn_ the language before writing yet another misinformed article.