Module 2 · Exercise 1 · ~25 min · Real Go code

Refactor a Non-Idiomatic File

A working but ugly Go file. Nine specific issues — each maps to a Module 2 lesson concept. Make it idiomatic; the tests must keep passing.

Where
cd module-02-idiomatic-go/exercises/exercise-01-refactor
go test -v ./...

Tests reference NewSubmitter, Submit, ErrTimeout — none of which exist yet. Refactor the starter file until the tests find them.

The nine smells

  1. Package name uses underscore + util suffix.
  2. Type name SubmitterClass stutters and uses Java-isms.
  3. Method DoSubmit has a redundant prefix.
  4. Receiver name this.
  5. String-concatenated errors instead of fmt.Errorf with %w.
  6. Returning a typed nil pointer as an interface (the trap from M1).
  7. ErrorTimeout sentinel naming.
  8. Missing doc comments on exported identifiers.
  9. Exported mutable config field that should be hidden.

What "idiomatic" means here

This is not aesthetic. Each smell maps to a real failure mode:

When green

Skim the diff. Imagine you're reviewing it. Would you approve? If yes, mark complete and move to Exercise 2 (writing your own table-driven test suite).