Version

For this course, Go homeworks and lectures will be based on Go version 1.9.1 1.9.2.

You can/should use https://play.golang.org/ to run examples from class and try things on your own.

Lecture Outline

  1. Language Basics
    • Intro to Go slides
    • Types
      • Built-in types
      • Variables
      • Zero-values
      • Blank identifier (_)
      • Foreshadowing (variables, pointers, memory allocation)
  2. Language Basics II
    • Variables
    • Constants
    • Pointers
    • Allocating memory
      • new() and make() – know the difference.
    • Slices
      • Creating slices
      • Slicing slices (and arrays)
    • Operators
  3. Slices, Unicode encoding
    • append()
      • How it works when the capacity of the slice is large enough
      • How it works when the capacity of the slice is not large enough
    • Unicode encoding
      • What is Unicode?
      • Encoding options
        • UTF-32 - []rune
        • UTF-16 - []uint16
        • UTF-8 - string or []byte
      • Diagrams representing how code points are stored in memory
  4. Branching, Loops, ‘n’ Functions
    • if/else
    • switch
      • Know the difference between switch statements in C++ and Go
    • Looping (for)
      • Counting
      • Sentinel
      • Infinite
      • Range
    • Reading files with ioutil.ReadFile
    • Functions
      • Definitions
      • Returning multiple results
      • Named results
      • defer
        • Stacking
    • Map
      • Zero-value for missing keys
      • Comma-ok pattern
  5. More Functions, Structs, and Methods
    • Function parameters
      • Always by value
      • Use a pointer if you want to effect change in the calling function
    • Functions as values
      • Pass ‘em as function parameters
      • Return ‘em from functions
      • Closures
    • Structs
    • Exporting (capitalization)
    • Methods
      • Not just for structs
      • Value Receivers
      • Pointer Receivers
      • When to choose value receiver vs. pointer receiver
  6. Concurrency Part 1
    • Concurrency
    • goroutines
      • say() and go say() example
    • Channels
      • How they work
      • Sending and receiving
      • Buffered and unbuffered channnels
    • Word count example
      • Sending results over a channel
      • Signaling completion over a channel
    • An Example
  7. Concurrency Part 2
    • Deadlock Review
    • The close() function
      • Checking for closed channels with the comma-ok pattern
      • Receiving until closed with a for-range loop
      • Examples
        • Closing a channel to signal the end of output
        • Closing a channel to signal the end of input
    • The select statement
    • Packages
      • Project structure
      • Importing packages
      • Exporting from packages
      • Brief notes on building with go build and go install
        • Don’t forget to set GOPATH
    • Concurrency is not parallelism
      • Listen to Rob Pike. It’s good for your brain.
  8. Interfaces
    • Additional facts about methods
    • Interface types
      • What they are
      • How to define an interface type
      • How to implement an interface
      • Zero value is nil
      • Method sets
        • Method sets are different for pointer and value receivers
      • Examples
    • The Empty Interface interface{}