Grokking Advanced Go
Vote

0% completed

​

go generate

This program prints the status of an order. It compiles, and it passes go vet, but the status it prints is wrong. An engineer added the constant Refunded and did not add a matching case to the String method.

Output:

order 1001: unknown

The constant list and the switch state the same fact twice, and nothing in the language compares the two copies. The compiler cannot report the omission, because a switch without a matching case is valid Go. How can a program write the second copy, so that the two can never disagree, and how does that program become part of a Go project?

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content