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

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

このコミットは、Go言語の標準ライブラリ内のコメントやエラー文字列に含まれる重複した単語(例:「of of」)を削除することを目的としています。主にコードの可読性と品質を向上させるためのクリーンアップ作業です。

コミット

commit e66d29cdcfc85cdd33f52b7739122a1d2db9197f
Author: David G. Andersen <dave.andersen@gmail.com>
Date:   Mon Jul 9 09:16:10 2012 +1000

    pkg: Removing duplicated words ("of of", etc.), mostly from comments.
    
    Ran 'double.pl' on the pkg tree to identify doubled words.
    One change to an error string return in x509;  the rest are in comments.
    Thanks to Matt Jibson for the idea.
    
    R=golang-dev, bsiegert
    CC=golang-dev
    https://golang.org/cl/6344089

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

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

元コミット内容

pkg: Removing duplicated words ("of of", etc.), mostly from comments. (パッケージ: 重複した単語(「of of」など)を削除、主にコメントから。)

Ran 'double.pl' on the pkg tree to identify doubled words.pkgツリーに対してdouble.plを実行し、重複した単語を特定した。)

One change to an error string return in x509; the rest are in comments.x509のエラー文字列の戻り値に1箇所変更があり、残りはコメント内の変更である。)

Thanks to Matt Jibson for the idea. (Matt Jibsonにアイデアを感謝する。)

R=golang-dev, bsiegert CC=golang-dev https://golang.org/cl/6344089

変更の背景

このコミットの主な背景は、Go言語の標準ライブラリ内のコード品質と可読性の向上です。コメントや文字列内に意図せず重複して記述された単語(例:「of of」、「a a」)は、読者にとって混乱を招き、プロフェッショナルな印象を損なう可能性があります。このような重複は、タイポやコピー&ペーストのミス、あるいは単に注意不足によって発生することがあります。

コミットメッセージによると、この変更はdouble.plというスクリプトをpkgツリー(Goの標準パッケージ群)に対して実行することで、自動的に重複単語を特定し、修正を行ったものです。Matt Jibson氏からのアイデアがきっかけとなっており、コミュニティによるコードベースの継続的な改善活動の一環として行われました。

特に、x509パッケージのエラー文字列の修正は、ユーザーや開発者がエラーメッセージを解釈する際の明確性を高める上で重要です。コメントの修正は直接的な機能変更には繋がりませんが、コードベース全体のメンテナンス性と新規開発者のオンボーディングに寄与します。

前提知識の解説

Go言語のパッケージ構造 (pkgツリー)

Go言語の標準ライブラリは、src/pkgディレクトリ以下に多数のパッケージとして構成されています。例えば、src/pkg/crypto/x509はX.509証明書に関する機能を提供し、src/pkg/regexpは正規表現エンジンを提供します。これらのパッケージはGoプログラムの基本的な構成要素であり、Go開発者にとって非常に重要です。このコミットは、これらの広範なパッケージにわたる品質改善を目的としています。

コメントの重要性

プログラミングにおけるコメントは、コードの意図、アルゴリズムの複雑な部分、特定の設計上の決定などを説明するために不可欠です。適切に書かれたコメントは、コードの可読性を高め、他の開発者(または未来の自分自身)がコードを理解し、保守するのを助けます。重複した単語を含むコメントは、そのプロフェッショナリズムを損ない、誤解を招く可能性もあります。

エラーメッセージの重要性

エラーメッセージは、プログラムが予期せぬ状況に遭遇した際に、その原因と状況をユーザーや開発者に伝えるための重要な手段です。明確で簡潔、かつ正確なエラーメッセージは、問題のデバッグと解決を大幅に容易にします。重複した単語を含むエラーメッセージは、混乱を招き、メッセージの意図を曖昧にする可能性があります。

double.plスクリプト

コミットメッセージに記載されているdouble.plは、Perlで書かれたスクリプトであると推測されます。その目的は、テキストファイル内で連続して同じ単語が2回出現するパターン(例:「the the」、「is is」)を検出することです。このようなスクリプトは、大規模なコードベースやドキュメントにおいて、手動では見落としがちなタイポや冗長な表現を自動的に特定するのに非常に有効です。

コードレビュープロセス (R=, CC=)

Goプロジェクトでは、変更がコミットされる前にコードレビューが行われます。コミットメッセージのR=はレビュアー(Reviewer)を示し、CC=はカーボンコピー(Carbon Copy)で通知される人々を示します。golang-devはGo開発者メーリングリストを指し、bsiegertは特定のレビュアーです。これは、変更がコミュニティによってレビューされ、承認されたことを示しています。

技術的詳細

このコミットは、主にテキストベースの変更であり、Go言語のランタイムやコンパイラの動作に直接的な影響を与えるものではありません。しかし、ソフトウェア開発におけるコード品質とメンテナンスの観点からは重要な意味を持ちます。

変更は以下の8つのファイルにわたっています。

  1. src/pkg/crypto/x509/verify.go
  2. src/pkg/database/sql/fakedb_test.go
  3. src/pkg/go/doc/reader.go
  4. src/pkg/html/template/url.go
  5. src/pkg/mime/grammar.go
  6. src/pkg/os/exec/exec.go
  7. src/pkg/regexp/regexp.go
  8. src/pkg/unsafe/unsafe.go

これらのファイルは、Goの標準ライブラリの様々な部分に属しており、証明書検証、データベーステスト、ドキュメント生成、HTMLテンプレート、MIMEタイプ解析、外部コマンド実行、正規表現、unsafe操作など、多岐にわたる機能に関連しています。

変更の性質は非常に単純で、ほとんどがコメント内の重複単語の削除です。唯一の例外はsrc/pkg/crypto/x509/verify.goで、ここではエラー文字列内の重複が修正されています。

例:

  • of of -> of
  • a a -> a
  • other other -> other
  • When opening a a fakeDriver's database -> When opening a fakeDriver's database
  • will always always be zero mod m -> will always be zero mod m

これらの変更は、コードのセマンティクス(意味)を変えることなく、純粋に表面的な改善に留まります。しかし、このような細かな修正の積み重ねが、大規模なオープンソースプロジェクトのコードベースの健全性を維持する上で不可欠です。

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

このコミットにおける「コアとなるコードの変更箇所」は、機能的なロジックの変更ではなく、主にコメントや文字列リテラル内の冗長な表現の削除です。以下に、各ファイルでの具体的な変更を示します。

src/pkg/crypto/x509/verify.go

--- a/src/pkg/crypto/x509/verify.go
+++ b/src/pkg/crypto/x509/verify.go
@@ -42,7 +42,7 @@ type CertificateInvalidError struct {
 func (e CertificateInvalidError) Error() string {
 	switch e.Reason {
 	case NotAuthorizedToSign:
-		return "x509: certificate is not authorized to sign other other certificates"
+		return "x509: certificate is not authorized to sign other certificates"
 	case Expired:
 		return "x509: certificate has expired or is not yet valid"
 	case CANotAuthorizedForThisName:
  • other other -> other (エラー文字列内)

src/pkg/database/sql/fakedb_test.go

--- a/src/pkg/database/sql/fakedb_test.go
+++ b/src/pkg/database/sql/fakedb_test.go
@@ -31,7 +31,7 @@ var _ = log.Printf
 //   INSERT|<tablename>|col=val,col2=val2,col3=?
 //   SELECT|<tablename>|projectcol1,projectcol2|filtercol=?,filtercol2=?
 //
-// When opening a a fakeDriver's database, it starts empty with no
+// When opening a fakeDriver's database, it starts empty with no
 // tables.  All tables and data are stored in memory only.
 type fakeDriver struct {
 	mu        sync.Mutex
@@ -234,7 +234,7 @@ func checkSubsetTypes(args []driver.Value) error {
 
 func (c *fakeConn) Exec(query string, args []driver.Value) (driver.Result, error) {
 	// This is an optional interface, but it's implemented here
-// just to check that all the args of of the proper types.
+// just to check that all the args are of the proper types.
 	// ErrSkip is returned so the caller acts as if we didn't
 	// implement this at all.
 	err := checkSubsetTypes(args)
@@ -249,7 +249,7 @@ func errf(msg string, args ...interface{}) error {
 
 // parts are table|selectCol1,selectCol2|whereCol=?,whereCol2=?
-// (note that where where columns must always contain ? marks,
+// (note that where columns must always contain ? marks,
 //  just a limitation for fakedb)
 func (c *fakeConn) prepareSelect(stmt *fakeStmt, parts []string) (driver.Stmt, error) {
 	if len(parts) != 3 {
  • a a -> a (コメント内)
  • of of -> are of (コメント内)
  • where where -> where (コメント内)

src/pkg/go/doc/reader.go

--- a/src/pkg/go/doc/reader.go
+++ b/src/pkg/go/doc/reader.go
@@ -494,7 +494,7 @@ func (r *reader) readPackage(pkg *ast.Package, mode Mode) {
 	r.funcs = make(methodSet)
 
 	// sort package files before reading them so that the
-// result result does not depend on map iteration order
+// result does not depend on map iteration order
 	i := 0
 	for filename := range pkg.Files {
 		r.filenames[i] = filename
  • result result -> result (コメント内)

src/pkg/html/template/url.go

--- a/src/pkg/html/template/url.go
+++ b/src/pkg/html/template/url.go
@@ -60,7 +60,7 @@ func urlProcessor(norm bool, args ...interface{}) string {
 		tc := s[i]
 		switch c {
 		// Single quote and parens are sub-delims in RFC 3986, but we
-// escape them so the output can be embedded in in single
+// escape them so the output can be embedded in single
 		// quoted attributes and unquoted CSS url(...) constructs.
 		// Single quotes are reserved in URLs, but are only used in
 		// the obsolete "mark" rule in an appendix in RFC 3986
  • in in -> in (コメント内)

src/pkg/mime/grammar.go

--- a/src/pkg/mime/grammar.go
+++ b/src/pkg/mime/grammar.go
@@ -22,7 +22,7 @@ func isTokenChar(r rune) bool {
 	return r > 0x20 && r < 0x7f && !isTSpecial(r)
 }
 
-// isToken returns true if s is a 'token' as as defined by RFC 1521
+// isToken returns true if s is a 'token' as defined by RFC 1521
 // and RFC 2045.
 func isToken(s string) bool {
 	if s == "" {
  • as as -> as (コメント内)

src/pkg/os/exec/exec.go

--- a/src/pkg/os/exec/exec.go
+++ b/src/pkg/os/exec/exec.go
@@ -16,7 +16,7 @@ import (
 	"syscall"
 )
 
-// Error records the name of a binary that failed to be be executed
+// Error records the name of a binary that failed to be executed
 // and the reason it failed.
 type Error struct {
 	Name string
  • be be -> be (コメント内)

src/pkg/regexp/regexp.go

--- a/src/pkg/regexp/regexp.go
+++ b/src/pkg/regexp/regexp.go
@@ -441,7 +441,7 @@ func (re *Regexp) ReplaceAllLiteralString(src, repl string) string {
 }
 
 // ReplaceAllStringFunc returns a copy of src in which all matches of the
-// Regexp have been replaced by the return value of of function repl applied
+// Regexp have been replaced by the return value of function repl applied
 // to the matched substring.  The replacement returned by repl is substituted
 // directly, without using Expand.
 func (re *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) string {
@@ -539,7 +539,7 @@ func (re *Regexp) ReplaceAllLiteral(src, repl []byte) []byte {
 }
 
 // ReplaceAllFunc returns a copy of src in which all matches of the
-// Regexp have been replaced by the return value of of function repl applied
+// Regexp have been replaced by the return value of function repl applied
 // to the matched byte slice.  The replacement returned by repl is substituted
 // directly, without using Expand.
 func (re *Regexp) ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte {
  • of of -> of (コメント内、2箇所)

src/pkg/unsafe/unsafe.go

--- a/src/pkg/unsafe/unsafe.go
+++ b/src/pkg/unsafe/unsafe.go
@@ -32,6 +32,6 @@ func Sizeof(v ArbitraryType) uintptr
 func Offsetof(v ArbitraryType) uintptr
 
 // Alignof returns the alignment of the value v.  It is the maximum value m such
-// that the address of a variable with the type of v will always always be zero mod m.
+// that the address of a variable with the type of v will always be zero mod m.
 // If v is of the form structValue.field, it returns the alignment of field f within struct object obj.
 func Alignof(v ArbitraryType) uintptr
  • always always -> always (コメント内)

コアとなるコードの解説

このコミットの「コアとなるコードの解説」は、変更された各行がどのように改善されたかを説明することに焦点を当てます。

src/pkg/crypto/x509/verify.go の変更

元のコード: return "x509: certificate is not authorized to sign other other certificates" 変更後: return "x509: certificate is not authorized to sign other certificates"

解説: この変更は、x509パッケージにおける証明書検証エラーメッセージの修正です。元のエラーメッセージには「other other」という重複した単語が含まれており、これは文法的に誤りであり、メッセージの明確性を損なっていました。修正により「other certificates」となり、証明書が他の証明書に署名する権限がないことを明確に伝える、より自然で正確なエラーメッセージになりました。これは、エラーハンドリングの品質向上に寄与します。

src/pkg/database/sql/fakedb_test.go の変更

元のコード(コメント内): When opening a a fakeDriver's database 変更後: When opening a fakeDriver's database

解説: fakeDriverのデータベースを開く際のコメントで、「a a」という重複がありました。これは単純なタイポであり、修正によって「a fakeDriver's database」と自然な英語表現になりました。

元のコード(コメント内): just to check that all the args of of the proper types. 変更後: just to check that all the args are of the proper types.

解説: 引数の型チェックに関するコメントで、「of of」という重複がありました。さらに、文脈から「are of」が正しい表現であるため、単語の重複を修正しつつ、文法的な誤りも修正されました。これにより、コメントの意図がより明確に伝わるようになりました。

元のコード(コメント内): (note that where where columns must always contain ? marks, 変更後: (note that where columns must always contain ? marks,

解説: where句の列に関するコメントで、「where where」という重複がありました。修正により「where columns」となり、コメントの可読性が向上しました。

その他のファイルの変更

他のファイル(src/pkg/go/doc/reader.go, src/pkg/html/template/url.go, src/pkg/mime/grammar.go, src/pkg/os/exec/exec.go, src/pkg/regexp/regexp.go, src/pkg/unsafe/unsafe.go)における変更も同様に、コメント内の重複単語(例: result result -> result, in in -> in, as as -> as, be be -> be, of of -> of, always always -> always)の削除です。

これらの変更はすべて、コードのセマンティクスに影響を与えることなく、コメントやエラーメッセージの品質、ひいてはコードベース全体の可読性とメンテナンス性を向上させるためのものです。このような細かな修正は、大規模なプロジェクトにおいてコードの「清潔さ」を保つ上で非常に重要であり、将来的な開発者がコードを理解しやすくなることに貢献します。

関連リンク

  • Go言語公式ドキュメント: https://go.dev/doc/
  • Go言語のコードレビュープロセスに関する情報 (Goの貢献ガイドラインなど): https://go.dev/doc/contribute
  • GoのIssue Tracker (Gerrit): https://go.dev/issue (コミットメッセージのhttps://golang.org/cl/6344089はGerritの変更リストへのリンクです)

参考にした情報源リンク