Prepare to dig into the Go programming language by establishing a development environment and looking at several examples of cool Go programs.
Beginning of class session 27.
Watch the Google I/O 2010 video: Go Programming
You can download the slides [pdf].
While watching the video, answer the questions below. The questions should match the order of the video. You’ll probably find that this takes a bit longer than the length of the video. The presenters blow through some of the code slides quickly. I found that I often wanted to stop the video and read the code. (Also note, the last half of the video is Q&A. I don’t ask any questions about that, but it is interesting viewing.)
Value interface defined in the slides (around 4:30), do types come at the beginning or end of parameter and method declarations?
BinaryOp method on Values is surprisingly like the binding operator (>>=) for the Maybe monad in Haskell. The Int type is analogous to Just, while the Error type is analogous to what?
Compressor example, the Java code in the talk uses the Template design pattern: an abstract class has a concrete method—here compress(Buffer in, Buffer out)—that calls another abstract method that must be implemented in a subclass. In Go, this same pattern is implemented how?
Note: The video glosses over channels a bit. Channels are essentially concurrent queues that processes can use to communicate values. A channel variable is declared like:
<name> chan <type>
for example done chan *Worker is a channel named done that transmits references to Worker objects, while result chan int is a channel named result that transmits int values. A cool feature of Go is that channels are first class, so one function can create a channel and then pass it to other functions that can read from or write to the channel.
In the Request type (25:05), what is the purpose for each of the two elements of the struct?
Print your answers and bring them to class session 27.
Install Go on your machine:
Do-it-yourselfers running Linux or Mac OS X can do a manual install following the instructions on the Go website.
If you’re on Windows, or on Mac OS X and prefer a pre-configured environment, you can install a VM running Ubuntu and Go by following these instructions.
If you want to really live on the edge, you could look at the Windows port on golang.org.
(A huge thanks to Tim Ekl for putting together the VM image and the installation instructions. I modified the instructions a bit, so if there are any errors, blame me for those.)
You’ll demonstrate your Go environment during class session 27.
Come to your regularly scheduled class session 27 (Thursday of week 7). Bring your laptop so you can demonstrate your Go environment to Sam (our TA). Bring a hardcopy of your answers to the questions about the video.