When I start a new feature in Go I keep reaching for the interface first. That order is wrong: write the concrete struct, and let interfaces show up at whatever consumes the dependency.
Posts tagged with backend
No framework, no container, no reflection scanning your struct fields at startup: Go's version of dependency injection is a constructor argument, and interfaces are what make that argument swappable.
Go collapses for, for-of, for-in, and forEach into one for, and a missing map key returns a zero value instead of undefined. Both are smaller languages on purpose.
A method is just a function with a receiver, a nil interface panics differently than a nil pointer, and iota isn't a TypeScript enum — three Go idioms I had to unlearn my TS assumptions for.
Defer's evaluation timing and named return values that get mutated after the return statement: two Go function features with no real TypeScript equivalent.
Slice headers, nil comparisons, and pointer fields for optional values: three places Go's syntax looks like TypeScript but the semantics don't match.
Six Go patterns that compile cleanly and quietly do the wrong thing: loop capture, typed nil, slice aliasing, shadowed err, defer in a loop, and range copies.
Go has no constructor keyword or new syntax, so the language leans on a plain function that returns a pointer, named NewX by convention.