Exercises for the O'Reily book "Leaning Go, 2nd Edition"
  • Go 94.5%
  • Makefile 5.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-09 22:21:54 -07:00
ch1 Chapter 1 complete 2026-07-27 17:08:47 -07:00
ch2 Chapter 2 complete 2026-07-27 20:43:47 -07:00
ch3 Chapter 3 complete 2026-08-09 22:21:43 -07:00
ch4 Chapter 4 complete 2026-08-09 22:21:54 -07:00
README.org Chapter 4 complete 2026-08-09 22:21:54 -07:00

Chapter Notes

Chapter 1

Chapter 2

  • Leading 0 with no prefix being octal is strange. I'm glad the book suggests not using it to reduce confusion.
  • Underscores allowed in numbers for place separation makes me happy.
  • rune literal :: single character, denoted with single quotes. Common escapes are runes; e.g., \n, \t, \', \\
  • interpreted string literal :: double quoted strings. Called interpreted because they interpret runes into single characters
  • raw string literal :: backquoted string, runes are not interpreted automatically
  • The result of integer division is also an integer, not a float.
  • += etc are valid for modifying; e.g., somevar *= 3
  • declaration lists :: Allows assigning multiple variables at once, as a part of a single visual block

       var (
      	a rune
      	b int = 10
      	c = 30
      )
  • := :: declaration and assignment shorthand. Like var but also does assignment to existing variables. only valid inside of functions

      a, b := 20, 40
      a := 60
  • Immutability in go is pretty limiting…
  • Similar to zig, unread variables cause a compile time error

    • I still think that while this makes sense at the end of a feature development, it's needlessly frustrating during development. I wish this could be turned off for dev builds and enforced for production builds.
  • Unicode allowed in var names is neat, but feel like they'd be a pain to actually use… glad the book calls this out.
  • Camel case over snake case.
  • wat?

    This is because Go uses the case of the first letter in the name of a package-level declaration to determine if the item is accessible outside the package.

Chapter 3

  • Weird restrictions on array typing. Hope that I hear more about why.
  • ok, so slices are the real arrays, I guess? That nomenclature is a bit obnoxious.
  • ok, so we finally found nil
  • nil isn't comparable, but a length of nil is 0?
  • Despite the kinda weird nomenclature around slices, I do like the split between length and capacity.

    • make(int[], 0, 10) is a neat way to start with nothing, knowing you probably won't go above 10
  • Slicing slices sharing a memory address seems like a really cool feature but a sharp knife. I already know that at some point I am going to accidentally change a value I don't expect with this.
  • map[string][]string is so difficult to visually parse.
  • The comma ok idiom makes me want to just have an :ok sigil again.

Chapter 4

  • Scoping a variable to an if block is neat. Gotta think on if it's actually useful though. I guess it kind of formalizes something I do fairly frequently: declaring a var right above a scope for use in it.

      if n := rand.Intn(10); n == 0 {
      	fmt.Println("That's too low")
      } else if n > 5 {
      	fmt.Println("That's too big:", n)
      } else {
      	fmt.Println("That's a good number:", n)
      }
  • I have… feelings… about Go only having a for loop.

    • no do...while I have less strong feelings about, I guess.
    • I feel like fewer keywords here is just going to make the code harder to understand.
    • I don't feel like for-range is an improvement over the more common for-in.
    • Having for-range give a random order during iteration, but a fixed order in a debugging print, feels likely to bite.
  • No fall-through on switch pleases me.
  • Scoping to a block will take practice to recognize, took me a couple of passes to understand how this is a "blank switch":

      switch someVar := 10; {
      	case 1,2,3,4:
      		// something
      	default:
      		// something else
      }
  • I appreciate the reasoning the author provides for deciding between a switch and if/else. Switch indicates a relationship between the evals.