Homework 11 — Programming Language Paradigms

Objectives

Prepare to dig into the Go programming language by establishing a development environment and looking at several examples of cool Go programs.

Due Date

Beginning of class session 27.

Tasks

  1. 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.)

    1. What’s the presenters’ goal for the video?
    2. True or False: Go uses classes and subclasses to support object-oriented programming.
    3. What does it mean that Go is concurrent not parallel?
    4. Looking at the Value interface defined in the slides (around 4:30), do types come at the beginning or end of parameter and method declarations?
    5. The 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?
    6. In Go, how do we declare that a type implements an interface? (Careful!)
    7. Thinking about the 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?
    8. True or False: Interfaces in Go are typically very small, that is, they have few methods.
    9. Around 17:00, the speaker claims that they could make the changes to RPC after the fact, without planning ahead. Is that really true? Justify your answer.
    10. 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?

    11. What are the three reasons are given (32:30) supporting the claim that Go can make programming more productive?
    12. Who would win in a fight, Tux the Linux Penguin, or the Go Gopher?

    Print your answers and bring them to class session 27.

  2. 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.

Turn-in Instructions

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.