Reference

Programming languages

Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.

Scope and conventions

TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.

Libraries: tools & testing

The toolchain around the code: building and packaging, testing, formatting and linting, debugging and profiling, and documentation.

Toolchain: node/npm/tsc, the go command, cargo, compilers + CMake

Go

One go command does almost everything: building, running, testing, dependency management (go get, go mod tidy), static checks (go vet), documentation (go doc) and toolchain upgrades. gofmt formats code, and nearly all Go code follows it. ./... means this package and every package below it.

Fragment

Terminal commands, run from the module folder.

terminal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
go mod init example.com/shop    # create go.mod
go get github.com/google/uuid   # add a dependency (go.mod + go.sum)
go run .                        # compile and run the current package
go build -o shop .              # build a binary
go test ./...                   # test this package and every package below it
go vet ./...                    # report suspicious code
gofmt -w .                      # format in place
go mod tidy                     # add missing and remove unused dependencies

Most used: go run ., go build, go test ./..., go mod tidy, go get, go vet, gofmt -w ., go get -tool for project-pinned tools (Go 1.24, run them with go tool), go work for multi-module workspaces, go doc fmt.Println.

go generate runs the //go:generate commands written in source files (stringer, mockgen, protoc). It never runs as part of go build, so generated files are committed or regenerated explicitly.

Testing: node:test, testing, #[test], GoogleTest

Go

testing is built into the toolchain. Test functions are named TestXxx(t *testing.T) in _test.go files and fail with t.Error or t.Fatal; there are no assertion helpers, just if statements. Table-driven tests with t.Run subtests are the convention. The same package provides benchmarks (BenchmarkXxx), fuzzing (FuzzXxx) and examples.

Complete file

A test file. Total usually lives in total.go in the same package; it is inline here to keep the example whole.

total_test.go
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
// total_test.go, run with: go test ./...
package order

import "testing"

func Total(prices []int) int {
    sum := 0
    for _, p := range prices {
        sum += p
    }
    return sum
}

func TestTotal(t *testing.T) {
    cases := []struct {
        name   string
        prices []int
        want   int
    }{
        {"adds prices", []int{40, 15}, 55},
        {"empty", nil, 0},
    }
    for _, c := range cases {
        t.Run(c.name, func(t *testing.T) {
            if got := Total(c.prices); got != c.want {
                t.Errorf("Total(%v) = %d, want %d", c.prices, got, c.want)
            }
        })
    }
}

Most used: go test ./..., t.Run, t.Errorf, t.Fatalf, t.Helper, t.Cleanup, httptest, go test -race, go test -run Name, t.Context (Go 1.24), for b.Loop() in benchmarks (Go 1.24), testing/synctest for time-dependent concurrent code (Go 1.25).

Formatting & linting: Prettier/ESLint, gofmt/vet, rustfmt/Clippy, clang-format/tidy

Go

gofmt defines the one Go formatting style, so there is nothing to configure, and goimports also fixes import lists. go vet ships with Go and catches likely bugs such as wrong printf arguments and copied mutexes. staticcheck adds many more checks, golangci-lint runs dozens of linters under one configuration, and govulncheck reports known vulnerabilities that your code actually reaches.

Fragment

Terminal commands, run from the project folder.

terminal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
gofmt -l .           # list files that are not formatted (-w rewrites them)
go vet ./...         # checks that ship with Go: printf arguments, copied locks...
staticcheck ./...    # the most widely used extra linter
golangci-lint run    # many linters at once, configured in .golangci.yml
govulncheck ./...    # known vulnerabilities in the code paths you use

Most used: gofmt -w, goimports, go vet ./..., staticcheck ./..., golangci-lint run, .golangci.yml, govulncheck ./....

Debugging & profiling tools: inspector, Delve + pprof, LLDB + flamegraph, sanitizers

Go

Delve (dlv) is the Go debugger, used directly or through VS Code and GoLand. Profiling is built in: runtime/pprof and the net/http/pprof handler write CPU, heap, goroutine and block profiles, and go tool pprof analyses them, including as flame graphs. go test runs benchmarks (-bench), the race detector (-race) and coverage (-cover), and go tool trace shows scheduler behaviour over time.

Fragment

Terminal commands, run from the project folder.

terminal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
dlv debug . -- -port 8080                # Delve: breakpoints, stepping, goroutines
go test -race ./...                      # data race detector
go test -bench . -benchmem               # benchmarks with allocation counts
go test -bench . -cpuprofile cpu.out     # write a CPU profile
go tool pprof -http :0 cpu.out           # explore it in the browser, flame graph included
GODEBUG=gctrace=1 ./app                  # print a line for every garbage collection

Most used: dlv debug, dlv test, go test -race, go test -bench . -benchmem, -cpuprofile and -memprofile, go tool pprof, import _ "net/http/pprof", go tool trace.

Documentation tools: TSDoc/TypeDoc, go doc, rustdoc, Doxygen

Go

Go documentation is plain comments: a comment directly before a declaration, starting with its name, documents it, and a comment before the package clause documents the package (or, for package main, the command). go doc prints documentation in the terminal, pkg.go.dev publishes it for every public module automatically, and [Name] links to other identifiers. Example functions (func ExampleWithTax) in _test.go files appear in the docs and run as tests.

Complete program

Complete program. Standard library: ships with Go, no install.

main.go
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
// Command pricing prints a price with tax.
package main

import "fmt"

// WithTax adds tax to a price in cents. The rate is a fraction,
// for example 0.2 for 20%, and the result is rounded to whole cents.
//
// Format the result with [fmt.Sprintf] when displaying it.
func WithTax(cents int, rate float64) int {
    return int(float64(cents)*(1+rate) + 0.5)
}

func main() {
    fmt.Println(WithTax(1000, 0.2))
}

Most used: // Name ... comments, // Package name ..., go doc pkg.Name, pkg.go.dev, Example functions with // Output:, [Name] links, Deprecated: paragraphs.