テーマ: go
-
新しいサービスにGoとRustのどちらを選ぶか:ベンチマークなしの判断手順
ベンチマークの俗説ではなく、文書化された言語の性質とチームの制約からGoかRustを選びます。メモリー管理モデル、エラーと並行処理のスタイル、負荷の形、必要な連携ライブラリ、そして2年後に誰が保守するかを見ます。
-
Cancellation and deadlines in Go with context.Context
Thread a context.Context from the incoming request through every call that can block, derive child contexts with WithTimeout or WithCancel, always call the cancel function, and check ctx.Done() in loops so that a client disconnect or a deadline stops the whole tree of goroutines instead of leaving them running.
-
Go の経過時間:シリアライズで単調時計の成分が失われる
プロセス内の時間計測を、永続化するタイムスタンプやプロセス間の期限方針と分けて扱います。
-
Go のインターフェース:暗黙の実装と nil ではない nil
Go の型は、必要なメソッドを持つことでインターフェースを満たし、宣言は不要である。そのため利用箇所で小さなインターフェースを作りやすい。ただし、インターフェース値は型と値の組なので、error インターフェースに格納した nil ポインターは nil と等しくない。
-
Go append のエイリアス:余剰容量と再割り当ての両経路をテストする
ビューへの追加が他から見える記憶領域を変更し得る場合、スライスの所有権を明示します。
-
Go のエラー処理:%w によるラップ、errors.Is、errors.As
Go の関数はエラーを通常の値として返します。fmt.Errorf と %w 書式指定子で文脈を加え、元のエラーにたどれるようにします。その後、文字列比較や == ではなく、センチネル値には errors.Is、型には errors.As(またはジェネリックな errors.AsType)を使ってチェーンを調べます。
-
Goroutines, channels and the sync package: Go concurrency in outline
A go statement runs a function call concurrently on a cheap, growable stack; channels move values between goroutines and block until both sides are ready; sync.WaitGroup, Mutex and Once cover the cases where sharing memory is simpler. A data race is a bug whose outcome the memory model only partly constrains, and the -race detector is the tool for finding it.
-
How much longer does it take an engineer from a dynamic language to become productive in Rust than in Go, and which concepts account for the gap?
Open question: Go is often described as quick to pick up and Rust as demanding, and the 2024 State of Rust survey reports that around 31% of non-users cite perceived difficulty; but few sources measure time to a first merged change, time to unsupervised code review, or which concepts (ownership, lifetimes, async, traits) consume that time for engineers arriving from Python, Ruby or JavaScript.
-
Go のサブテストを使ったテーブル駆動テスト
名前付きのケースを並べたスライスを一つのテスト関数で走査し、各ケースを t.Run で実行する。ケースをデータとして表せるうえ、go test -run 'TestX/name' で一件だけ選べる。t.Parallel、t.Helper、t.Cleanup を使えば、ループの速さと読みやすさを保てる。
-
Go の競合検出の範囲:問題のない実行から未実行の経路については何も分からない
go test -race の結果を、起動と終了を含む実際に実行した並行処理経路に結び付けます。
-
Rust traits versus Go interfaces: explicit impl, implicit satisfaction
Both languages abstract over behaviour without class hierarchies, but a Go type satisfies an interface by merely having the methods, while a Rust type implements a trait only through an explicit impl block subject to the orphan rule; Rust additionally separates compile-time generics (monomorphised) from dyn trait objects (dynamic dispatch), a choice Go makes for the programmer.
-
Go モジュール:go.mod、go.sum、メジャーバージョンの接尾辞
Go モジュールは、go.mod で記述する、バージョンを持つパッケージのツリーです。go コマンドは最小バージョン選択で依存関係の版を決め、go.sum でダウンロードを検証します。1 より大きいメジャーバージョンにはモジュールパスの /v2 形式の接尾辞を要求するため、互換性のない版は異なるインポートパスを持ちます。
-
Go のミューテックスのコピー:保護する状態に対するロックの同一性を保つ
使用を開始したミューテックスを含む構造体をコピーし得る、値レシーバー、代入、コンテナー操作を監査する。
機械可読: JSON