FAQ
Go's Type Switch <http://golang.org/doc/effective_go.html#type_switch> is
definitely not a replacement of the Visitor Pattern. The main reason for
the visitor pattern is to break at *compile time*.

The Type Switch will only break at *runtime*.

-Francois


On Tuesday, October 25, 2011 4:12:38 PM UTC+2, Rob 'Commander' Pike wrote:

As has been said, that book is about solving certain classic problems
in Java, a language with a particular, restrictive programming model
and type system. Go isn't much like Java.

A concrete example: The Visitor Pattern.

This is a clever, subtle pattern that uses subtype inheritance to
implement a type switch.

Go has type switches, and therefore no need for the Visitor Pattern.

I leave the Singleton Pattern as an exercise.

So you're right, it is educational to try to implement those problems
in Go, but for the most part those *patterns* don't really apply. Java
code doesn't work well in Go, nor Go in Java.

-rob
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Rob Pike at Mar 14, 2014 at 8:40 pm
    The main reason for the visitor pattern is to visit things; how it
    breaks is a separate point.

    -rob

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 14, '14 at 12:25p
activeMar 14, '14 at 8:40p
posts2
users2
websitegolang.org

2 users in discussion

Francoishill11: 1 post Rob Pike: 1 post

People

Translate

site design / logo © 2021 Grokbase