Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[インデックス 12717] ファイルの概要

このコミットは、Go言語の公式ドキュメントの一部である doc/articles/go_command.html ファイルに対する変更です。このファイルは、Goコマンド(go build, go get など)の動作原理と、Goエコシステムにおける「設定よりも規約」という哲学について解説している記事です。

コミット

  • コミットハッシュ: cec67568e98d884b9cc2a9be88c8306fd2556800
  • 作者: Rob Pike r@golang.org
  • 日付: 2012年3月22日 木曜日 17:59:06 +1100

GitHub上でのコミットページへのリンク

https://github.com/golang/go/commit/cec67568e98d884b9cc2a9be88c8306fd2556800

元コミット内容

doc/articles/go_command.html: nits
Fix some English mistakes and minor inaccuracies.

R=golang-dev, jsing
CC=golang-dev
https://golang.org/cl/5885046

変更の背景

このコミットの背景は、Go言語の公式ドキュメント doc/articles/go_command.html の品質向上にあります。コミットメッセージにある「nits」とは、些細な修正、特に文章の誤りや不正確な記述を指します。具体的には、英語の文法的な誤りや、Goコマンドの動作に関する記述の軽微な不正確さを修正することが目的でした。

Go言語は「設定よりも規約 (Convention over Configuration)」という設計思想を強く持っており、特にパッケージ管理においてその思想が顕著です。初期のGoエコシステムでは、多くの開発者が他の言語の慣習に従い、パッケージのインストールやビルドに独自のルールを適用しようとしました。しかし、Goの設計者たちは goinstall (後に go get に置き換えられる) コマンドとその規約(インポートパスがソースコードのURLから導出されること、ソースの保存場所がインポートパスから導出されること、ディレクトリが単一のパッケージに対応すること、ビルドがソースコードの情報のみを使用すること)を一貫して推奨してきました。

このドキュメントは、これらのGoの重要な規約を説明するものであり、その内容が正確で分かりやすいことは非常に重要です。このコミットは、そのドキュメントの記述をより明確にし、読者にとっての理解を深めるための微調整として行われました。特に、goinstallgo get に置き換えられたことにも言及しており、時間の経過とともにGoツールが進化していることを反映しています。

前提知識の解説

Go言語のパッケージ管理と「設定よりも規約」

Go言語の設計哲学の根幹には「設定よりも規約 (Convention over Configuration)」があります。これは、開発者が多くの設定ファイルを書く代わりに、特定の規約に従うことでシステムが自動的に動作するという考え方です。Goのパッケージ管理において、この原則は特に重要です。

  • GOPATH: Go 1.11以前では、Goのソースコード、コンパイル済みバイナリ、パッケージはすべて GOPATH という環境変数で指定されたワークスペース内に配置されることが規約でした。GOPATH は、Goプロジェクトのルートディレクトリとして機能し、src, pkg, bin の3つのサブディレクトリを持ちます。
    • src: ソースコードが配置されます。インポートパスは、GOPATH/src からの相対パスで解決されます。例えば、github.com/user/repo というパッケージは GOPATH/src/github.com/user/repo に配置されます。
    • pkg: コンパイル済みのパッケージオブジェクトが配置されます。
    • bin: コンパイル済みの実行可能ファイルが配置されます。
  • インポートパス: Goでは、パッケージのインポートパスは、そのパッケージのソースコードがどこにあるかを示すURLのような形式で記述されます(例: import "fmt", import "github.com/gin-gonic/gin")。このインポートパスは、go get コマンドがソースコードをダウンロードする際のURLとしても機能します。
  • goinstallgo get:
    • goinstall: Goの初期に存在したコマンドで、リモートリポジトリからパッケージをダウンロードし、GOPATH にインストールする役割を担っていました。これはGoの「設定よりも規約」の思想を体現する最初のツールの一つでした。
    • go get: goinstall の後継として導入されたコマンドです。go get は、指定されたインポートパスに基づいて、対応するソースコードをバージョン管理システム(Git, Mercurialなど)からダウンロードし、GOPATH 内の適切な場所に配置します。また、そのパッケージが依存する他のパッケージも再帰的にダウンロードします。これにより、開発者は依存関係を手動で管理することなく、簡単にプロジェクトをセットアップできるようになりました。go get は、Goモジュールが導入されるまで、Goの主要な依存関係管理ツールでした。
  • 単一パッケージの原則: Goの規約では、ソースツリー内の各ディレクトリは単一のパッケージに対応します。これにより、コードの構造が明確になり、パッケージのインポートと管理が容易になります。
  • ソースコードのみでのビルド: Goのビルドシステムは、基本的にソースコード内の情報のみを使用してビルドを行います。Makefile のような外部の設定ファイルに依存することは推奨されません。これにより、ビルドプロセスがシンプルになり、再現性が高まります。

これらの規約に従うことで、Goエコシステムはシンプルで強力なものとなり、開発者はプロジェクトのセットアップや依存関係の管理に煩わされることなく、本質的な開発に集中できるようになります。

技術的詳細

このコミットは、doc/articles/go_command.html ファイル内のテキストコンテンツに対して、以下の3つの修正を行っています。

  1. 「the convention」から「those conventions」への変更:

    • 変更前: The system works only to the extent that the convention is followed.
    • 変更後: The system works only to the extent that those conventions are followed.
    • 解説: 「規約 (convention)」という単数形から「それらの規約 (those conventions)」という複数形に変更されています。これは、Goエコシステムが単一の規約だけでなく、複数の関連する規約(インポートパスの導出、ソースの保存場所、単一パッケージの原則など)の集合体によって成り立っていることをより正確に表現するためです。これにより、Goの設計思想がより包括的に伝わるようになります。
  2. 「the old goinstall command」から「the goinstall command」への変更:

    • 変更前: about the old <code>goinstall</code> command
    • 変更後: about the <code>goinstall</code> command
    • 解説: goinstall コマンドが go get に置き換えられたことを考慮し、「古い (old)」という形容詞が削除されました。これは、goinstall がもはや主要なツールではないことを示唆しつつも、その歴史的な役割を不必要に強調しないようにするためです。ドキュメントの記述をより簡潔かつ正確に保つための修正です。
  3. 「for it」から「as a result」への変更:

    • 変更前: The Go ecosystem is simpler and more powerful for it.
    • 変更後: The Go ecosystem is simpler and more powerful as a result.
    • 解説: 「for it」(そのために)という表現を「as a result」(結果として)に変更しています。これは、Goの規約に従うことによってGoエコシステムがシンプルかつ強力になったという因果関係をより明確に、かつ自然な英語表現で示すためです。

これらの変更はすべて、ドキュメントの可読性、正確性、そして英語としての自然さを向上させるための「nits」(些細な修正)に分類されます。

コアとなるコードの変更箇所

--- a/doc/articles/go_command.html
+++ b/doc/articles/go_command.html
@@ -42,12 +42,12 @@ statements.</p>
 <h2>Configuration versus convention</h2>
 
 <p>The way to achieve the simplicity of a configuration-free system is to
-establish conventions. The system works only to the extent that the convention
-is followed. When we first launched Go, many people published packages that
+establish conventions. The system works only to the extent that those conventions
+are followed. When we first launched Go, many people published packages that
 had to be installed in certain places, under certain names, using certain build
 tools, in order to be used. That's understandable: that's the way it works in
 most other languages. Over the last few years we consistently reminded people
-about the old <code>goinstall</code> command
+about the <code>goinstall</code> command
 (now replaced by <a href="/cmd/go/#Download_and_install_packages_and_dependencies"><code>go get</code></a>)
 and its conventions: first, that the import path is derived in a known way from
 the URL of the source code; second, that that the place to store the sources in
@@ -55,7 +55,7 @@ the local file system is derived in a known way from the import path; third,
 that each directory in a source tree corresponds to a single package; and
 fourth, that the package is built using only information in the source code.\n Today, the vast majority of packages follow these conventions.\n-The Go ecosystem is simpler and more powerful for it.</p>\n+The Go ecosystem is simpler and more powerful as a result.</p>\n```

## コアとなるコードの解説

上記のdiffは、`doc/articles/go_command.html` ファイル内の3つの異なる箇所に対するテキストの修正を示しています。

1.  **行44-45の変更**:
    *   `-establish conventions. The system works only to the extent that the convention`
    *   `+establish conventions. The system works only to the extent that those conventions`
    *   この変更は、「the convention」(その規約)を「those conventions」(それらの規約)に修正しています。Goのパッケージ管理には複数の規約が存在するため、単数形から複数形にすることで、より正確な表現になっています。

2.  **行49の変更**:
    *   `-about the old <code>goinstall</code> command`
    *   `+about the <code>goinstall</code> command`
    *   ここでは、`goinstall` コマンドの前にあった「old」(古い)という形容詞が削除されています。`goinstall` は `go get` に置き換えられましたが、ドキュメント上ではその歴史的な役割を不必要に強調せず、単にコマンド名として言及する形に修正されています。

3.  **行57の変更**:
    *   `-The Go ecosystem is simpler and more powerful for it.</p>`
    *   `+The Go ecosystem is simpler and more powerful as a result.</p>`
    *   「for it」(そのために)という表現が「as a result」(結果として)に修正されています。これにより、Goの規約に従うことがエコシステムをシンプルかつ強力にする「結果」であるという因果関係がより明確に、かつ自然な英語で表現されています。

これらの変更は、Goのドキュメントの品質を向上させ、読者にとってより正確で理解しやすい情報を提供することを目的としています。

## 関連リンク

*   Go言語公式ドキュメント: [https://go.dev/doc/](https://go.dev/doc/)
*   Goコマンドのドキュメント: [https://go.dev/cmd/go/](https://go.dev/cmd/go/)
*   Go Modules (Go 1.11以降のパッケージ管理): [https://go.dev/blog/using-go-modules](https://go.dev/blog/using-go-modules)

## 参考にした情報源リンク

*   GitHub: golang/go commit cec67568e98d884b9cc2a9be88c8306fd2556800: [https://github.com/golang/go/commit/cec67568e98d884b9cc2a9be88c8306fd2556800](https://github.com/golang.com/go/commit/cec67568e98d884b9cc2a9be88c8306fd2556800)
*   Go言語の「設定より規約」に関する一般的な情報源 (Go公式ブログやドキュメント):
    *   Go Blog: [https://go.dev/blog/](https://go.dev/blog/)
    *   Go Documentation: [https://go.dev/doc/](https://go.dev/doc/)
*   `goinstall` から `go get` への移行に関する情報 (当時のGoコミュニティの議論やリリースノート):
    *   Go 1 Release Notes (go getの導入): [https://go.dev/doc/go1](https://go.dev/doc/go1)
    *   A Tour of Go (古いバージョンの情報): [https://go.dev/tour/](https://go.dev/tour/) (ただし、現在のバージョンでは情報が更新されている可能性あり)
*   Rob Pike氏のGoに関する記事や講演 (Goの設計思想に関する洞察):
    *   Go at Google: Language Design in the Service of Software Engineering: [https://talks.golang.org/2012/go-at-google.slide](https://talks.golang.org/2012/go-at-google.slide) (2012年のスライド)
    *   Go Proverbs: [https://go-proverbs.github.io/](https://go-proverbs.github.io/)