'Let's Code' is a series in which we collaboratively write Go code in real time, without preparation or a safety net. You'll see mistakes, you'll see bugs, you'll see us getting things wrong and backtracking our bad decisions. That's part of the fun... at least, we hope so.
This is the GitHub repo for the lunar lander project: https://github.com/bitfield/lander
Check out the complete Let's Code series on YouTube. Here are a few hand-picked episodes.
Kicking off a new project, John and Mike are live-coding without a safety net! How quickly can we get a basic Lunar Lander game up and running, and playable? Realistic physics be damned; we made a game!
Bukola and John attempt to whip the Lander project into shape by creating a package and some tests. Along the way, we make some important design decisions, steal some ideas from ‘Elite’, and have considerable fun.
Josh and John continue packagizing the code, and consider how to test a function that prints output to the terminal. (Answer: give it a fake terminal to print to!)
Umang and John refactor the game to remove some pesky global variables, and seal them up safely in a 'game state' object which they can pass around.
This week, Andy and John work on reading the control input from the player, and we talk interfaces. Readers! Writers! Oh my!
This week, Thiago and John get physical with the UpdateWorld method, and hit a big milestone: the game is running again!
This week, Jakub and John pick up the project after a five-month break, and ease themselves gently back into the code by reading the tests. We briefly review the game machinery, and talk about the value of checking irrelevant errors in tests, and why tests should be order-independent.
Jakub and John continue their look at the 'lander' package, along the way discussing the shortcomings of 'float32', procedural galaxy generation in Elite, re-flashing a Mars helicopter over a slow link, and whether or not there's any Go code running in space. Topics covered: idempotent tests, go-cmp, reflect.DeepEqual, floating point, overflow, Elite, procedural generation, pseudo-random, embedded systems.
Jakub and John discuss the joys and frustrations of bikeshedding project structure, the flexibility of interfaces, and how physics even works. Topics covered: TDD, test coverage, pointers, DOOM.
More space-based shenanigans as Jakub and John discuss the value of self-discipline, Zen mountain-climbing strategy, and why you should always be writing libraries. Topics covered: refactoring, TDD, camel case
John explains his unwillingness to make even reasonable assumptions, and Jakub demonstrates why you should write lots of brain-dead tests, as the crowdsourced development of a space game in Go continues. Topics covered: VS Code, math.Abs, table test, defensive programming.
The adventure on top of Zen Mountain continues, with thoughts from Jakub and John on how to test programs that interact with users, writing tests from the middle out, and what programmers really mean by the word "trivial". Topics covered: co-authored-by, TODO comments, bytes.Buffer.
Jakub and John continue mashing keys on the lunar lander project, with digressions about why Gophers love 'io.Reader', the dark secret of how programs really start, and how to stay calm in the face of 100 compiler errors. Topics covered: variadic arguments, functional options, project structure, io.Reader, io.Writer, slice, range, first class functions.
The awesome power of functional options come into play, as Jakub and John discuss variadic parameters and the 'unroll' operator, why discipline is good for you, and the cognitive enhancement available from Dave Cheney's blog. Topics covered: io.Reader, function literal, functional options, bytes.Buffer, variadic functions.
The lander continues its powered descent, as Jakub and John complete the refactoring of all the game logic into a self-contained package. Along the way, we discuss getting the computer to write your test expectations, why the standard library has no special privileges, and the confidence-enhancing effect of being able to watch experienced programmers screw up. Topics covered: panic, pointers, stack trace, interfaces, refactoring, Jon Bodner's "Learning Go", JSON marshal/unmarshal, unexported fields, go.mod, "Just For Func".