Articles
- Functional Options Pattern: When It Helps and When It Doesn'tOct 2026Functional options keep the constructor stable as optional configuration grows, while providing defaults and validation in one place. This pattern suits APIs with many independent options, but only adds indirection if configuration is minimal or all fields are required.
- Go Generics: Practical Cases Without OverengineeringOct 2026Generics let a single implementation work for multiple types with compile-time checking. Use type parameters when the algorithm is truly the same for many types, then restrict operations through the smallest possible constraint.
- `defer`, `panic`, and `recover`: When to Use ThemOct 2026Use `defer` for cleanup that must run on every exit path, with LIFO execution order and arguments evaluated when the `defer` statement runs. Use `panic` only for conditions that cannot be continued, then place `recover` at a clear boundary to turn the panic into a controlled failure.
- Go Project Structure — Package, Module, and WorkspaceOct 2026One folder = one package. One go.mod = one module. go.work combines local modules during development. The compiler controls visibility: lowercase is invisible across packages, internal/ cannot be imported from outside the subtree.
- Value vs Pointer Semantics in GoOct 2026Everything in Go is passed by value — arguments, range elements, method receivers. Copies are shallow — structs containing maps/slices still share backing data. Mutations to a copy aren't visible unless you pass a pointer.
- Slices Explained: Length, Capacity, and Backing ArraysOct 2026A Go slice is a descriptor that holds a pointer to a backing array, a length, and a capacity. Slicing creates an alias to the same array, while append may reuse the old array or allocate a new one, so the result must be used again.
- Maps in Go: Zero Values, Mutability, and ConcurrencyOct 2026Maps in Go distinguish default values from the presence of a key through comma-ok, and the delete operation is safe for keys that don't exist. Maps are not safe to access concurrently without synchronization, so a wrapper with RWMutex keeps reads and writes safe.
- Go Interfaces: Implicit Implementation and Practical DesignOct 2026Go interfaces are satisfied implicitly by types with a matching method set, without an implements declaration. Small interfaces on the consumer side keep dependencies narrow, while the method set difference between T and *T determines which value satisfies the contract.
- Error Handling in Go: Wrapping, Checking, and Sentinel ErrorsOct 2026Errors in Go are values that can be given context while preserving their cause using `%w`. Use `errors.Is` to match sentinel errors and `errors.As` to extract typed errors from an error chain without relying on message text.