Go Standard Library
The parts of the standard library people reimplement by hand: strings.Builder, the Split and Trim families, strconv against fmt.Sprintf, the fmt verbs, sort.Slice, encoding/json tags, bytes against strings, and io.Reader and io.Writer. Ten packages where a built-in already does the job, and one behaviour in each that is not what you assumed.
Who it is for
Reaches for a dependency before the built-in.
The behaviour people get wrong after they are already productive in the language.
You will get the most out of it if you have written Go recently enough to read it without effort, and have been surprised by it at least once. If you are picking the language up for the first time, start with Go Essentials and come back to this one.
How long it takes
90 graded questions at roughly 45 seconds each is about 68 minutes of answering in total.
At the default five questions a day, and because the session mixes in your other courses, expect around 18 days — call it 3 weeks — to see everything once, plus a few weeks of thinning reviews after that before it is all mastered.
A question is mastered on the third correct answer, once the gap between reviews has grown past a week — so a course cannot be finished in a weekend however long you sit with it.
Question mix
- 60 multiple choice
- 10 concept cards
- 10 predict the output
- 10 put it in order
- 10 matching questions
Syllabus
What you will be asked about
-
01
strings.Builder and Joining
Build a string with strings.Builder or strings.Join instead of repeated concatenation, and say what each one costs.
-
02
Split, SplitN and Fields
Predict the length and contents of a Split result, including the empty-string, empty-separator and trailing-separator cases.
-
03
Trim: cutsets versus prefixes
Choose between the Trim family and the TrimPrefix family, and predict what a cutset removes.
-
04
strconv versus fmt.Sprintf
Convert between numbers and text with strconv, and say what fmt.Sprintf does differently.
-
05
What each fmt verb shows
Pick between %v, %+v, %#v, %q and %T, and say what each one reveals about a value.
-
06
sort.Slice and what stable means
Sort a slice in place with the sort package, and say when SliceStable is the one you need.
-
07
Marshalling with tags
Predict the JSON a struct produces, including what tags change and what unexported fields do.
-
08
Strings, bytes and runes
Say whether an operation on a string is counting bytes or runes, and choose between the strings and bytes packages.
-
09
io.Reader and io.Writer
Satisfy io.Writer with a single method, and predict what Read, io.Copy and io.ReadAll leave behind.
-
10
errors and fmt together
Wrap an error with fmt.Errorf and retrieve it again with errors.Is and errors.As.
8 more topics, and all 90 questions
Go Standard Library is a Pro course. One subscription opens it and every other course in the catalogue, including the ones still being written.
A question from this course
strings.Builder and Joining
What does this print?
package main
import (
"fmt"
"strings"
)
func main() {
var b strings.Builder
b.WriteString("go")
b.WriteString("lang")
fmt.Println(b.String(), b.Len())
}
Show the answer
A golang 6
You may have expected a panic because b was never initialised with new or make; the zero Builder is documented as usable and its internal slice is simply nil until the first write. Len reports bytes written, which is 6, not the two calls that wrote them. Println puts a single space between its operands, which is where the gap comes from.
The rest of the track
Go at every depth
Go Essentials
The behaviour underneath Go's small syntax. Every variable starts at a usable zero value, a string is a sequence of bytes until you range over it, and an unused import stops the build.
Go Core
The places Go still surprises people who write it every day. append sometimes mutates the caller's array and sometimes does not, an interface holding a nil pointer is not nil, and a deferred call can rewrite a named return value.
Go Data & Collections
Slices, maps and the places they surprise people. Backing arrays shared by accident, append that sometimes writes into the caller's memory, nil maps that read fine and panic on write, and the randomised iteration order that makes a passing test lie.
Go Errors & Edge Cases
The error convention taken seriously: wrapping with %w, errors.Is against errors.As, sentinel values and custom types. Ends with the traps - a nil pointer that is not a nil error, a recover that only works one frame up, and the Close whose error everyone drops.
Go Idioms & Pitfalls
The Go people write out of habit that another language taught them: naked returns, GetX accessors, interfaces declared by the producer, else after a return, errors dropped into the blank identifier, panic as control flow, pointers for small structs, any where a type parameter belongs, a channel where a mutex was simpler, and embedding mistaken for inheritance. Ten habits, each with a snippet that shows what the compiler actually does.
Go Advanced
The runtime and type-system behaviour that catches confident Go programmers: typed nils, method sets, closed and nil channels, and a defer that rewrites a named return. Every snippet is one you could be handed in a code review.
Go Performance
What allocation actually costs in Go, and how to see it: escape analysis, slice and map preallocation, strings.Builder, interface boxing, sync.Pool, and a garbage collector described as it is rather than as folklore. Every claim is one you can check with a benchmark or an escape report.
Go Testing
What a Go test actually asserts, and where that claim is weaker than it looks. Table-driven cases and subtest names, t.Error against t.Fatal, reflect.DeepEqual and nil against empty, comparing floats, matching errors with errors.Is, seams instead of mocks, golden files, b.N and t.Cleanup.
Go Interview Questions
The questions Go interviewers actually ask, and the answer under the answer. Slice aliasing, the nil map, the typed-nil interface, WaitGroups and select, defer against named returns, wrapped errors, embedding, receivers, and a closing round of what does this print.
Start Go Standard Library
in tomorrow’s session.
Enrol and this course joins your daily five, mixed in with everything else you are studying — 90 questions spread over about 18 days rather than dropped on you at once.
Browse the catalogue