[インデックス 12783] ファイルの概要
このコミットは、Go言語の公式ドキュメントの一部である「Laws of Reflection」という記事内のリンクを、絶対パスから相対パスに変更するものです。これにより、ドキュメントの可搬性と保守性が向上します。
コミット
commit 14da5298cd2b2099909545976e7cb8e5c8fadae9
Author: Andrew Gerrand <adg@golang.org>
Date: Tue Mar 27 20:53:16 2012 +1100
doc: use relative links in Laws of Reflection article
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5924050
GitHub上でのコミットページへのリンク
https://github.com/golang/go/commit/14da5298cd2b2099909545976e7cb8e5c8fadae9
元コミット内容
doc: use relative links in Laws of Reflection article
このコミットメッセージは、Go言語のドキュメントにある「Laws of Reflection」という記事において、リンクの記述方法を相対パスに変更したことを示しています。
変更の背景
ウェブサイトやドキュメントにおいて、リソースへのリンクは非常に重要です。リンクには大きく分けて「絶対パス」と「相対パス」の2種類があります。
- 絶対パス (Absolute Path): ドメイン名から始まる完全なURLです。例:
http://golang.org/pkg/io/
- 相対パス (Relative Path): 現在のドキュメントの位置を基準としたパスです。例:
/pkg/io/
このコミットが行われた背景には、以下の理由が考えられます。
- 可搬性の向上: ドキュメントが異なるドメインやサブディレクトリに移動された場合でも、相対パスを使用していればリンクを修正する必要がありません。絶対パスの場合、ドメイン名やパスの変更に合わせて全てのリンクを更新する必要があり、これは手間がかかりエラーの原因にもなります。
- 開発環境での利便性: ローカル環境でドキュメントを開発・テストする際、絶対パスで記述されたリンクは外部のインターネット接続を必要とするか、ローカルサーバーの設定を複雑にする可能性があります。相対パスであれば、ローカルファイルシステム上でも正しくリンクが機能します。
- パフォーマンスの最適化: ごくわずかな差ではありますが、絶対パスはドメイン解決のオーバーヘッドを伴う可能性があります。相対パスは、ブラウザが現在のドメインを基準にリソースを解決するため、このオーバーヘッドを回避できます。
- 保守性の向上: ドメイン名が変更された場合でも、ドキュメント内のリンクを一括で変更する必要がなくなるため、長期的な保守が容易になります。
「Laws of Reflection」はGo言語の重要な概念であるリフレクションについて解説した記事であり、Goの公式ウェブサイトにホストされています。このコミットは、その記事の品質と保守性を向上させるための一般的なウェブ開発のベストプラクティスに沿った変更と言えます。
前提知識の解説
1. Go言語のリフレクション (Reflection)
Go言語におけるリフレクションとは、プログラムの実行時に型情報(型、メソッド、フィールドなど)を検査したり、値を動的に操作したりする機能です。Go言語では、reflect
パッケージがこの機能を提供します。
reflect.Type
: Goの型に関する情報(名前、カテゴリ、メソッドなど)を表します。reflect.Value
: Goの値に関する情報(実際のデータ、操作可能性など)を表します。
リフレクションは、汎用的なシリアライザ/デシリアライザ、ORM (Object-Relational Mapping)、RPC (Remote Procedure Call) フレームワーク、テストツールなど、コンパイル時に型が確定しない状況で動的に処理を行う必要がある場合に利用されます。しかし、リフレクションは型安全性を損なう可能性があり、パフォーマンスオーバーヘッドも伴うため、必要最小限に留めることが推奨されます。
「Laws of Reflection」の記事は、Goのリフレクションの基本的な概念と、reflect
パッケージのType
とValue
の利用方法について解説しています。
2. HTMLにおけるリンク (Hyperlinks)
HTMLでは、<a>
タグを使用してハイパーリンクを作成します。href
属性にリンク先のURLを指定します。
- 絶対パスの例:
<a href="http://example.com/path/to/page.html">絶対パスのリンク</a>
- 相対パスの例:
- ルート相対パス: ドメインのルートディレクトリからのパス。
この場合、<a href="/path/to/page.html">ルート相対パスのリンク</a>
http://example.com/path/to/page.html
にリンクされます。 - ドキュメント相対パス: 現在のHTMLファイルからの相対的なパス。
<!-- 現在のディレクトリ内の別のファイル --> <a href="another_page.html">別のページ</a> <!-- 親ディレクトリのファイル --> <a href="../parent_page.html">親のページ</a> <!-- サブディレクトリのファイル --> <a href="sub_dir/sub_page.html">サブディレクトリのページ</a>
- ルート相対パス: ドメインのルートディレクトリからのパス。
このコミットでは、主にルート相対パスへの変更が行われています。
技術的詳細
このコミットの技術的詳細は、HTMLドキュメント内の<a>
タグのhref
属性の値を変更することに集約されます。具体的には、http://golang.org/
で始まる絶対URLを、/
で始まるルート相対URLに置き換えています。
変更されたリンクは以下の通りです。
http://golang.org/pkg/io/
->/pkg/io/
io
パッケージへのリンク。io.Reader
とio.Writer
の例で参照されています。
http://golang.org/pkg/reflect
->/pkg/reflect/
reflect
パッケージへのリンク。リフレクションの基本型であるType
とValue
の説明で参照されています。
http://golang.org/pkg/reflect/#Type
->/pkg/reflect/#Type
reflect
パッケージ内のType
型へのアンカーリンク。
http://golang.org/pkg/reflect/#Value
->/pkg/reflect/#Value
reflect
パッケージ内のValue
型へのアンカーリンク。
http://golang.org/pkg/reflect/#Type.TypeOf
->/pkg/reflect/#Type.TypeOf
reflect.TypeOf
関数のドキュメントへのアンカーリンク。
また、Russ Cox氏のブログ記事へのリンクは、元々絶対パスでしたが、これはGoの公式ドメイン外のリンクであるため、変更されていません。
<a href="http://research.swtch.com/2009/12/go-data-structures-interfaces.html">detailed blog post</a>
この変更は、HTMLの構文規則に完全に準拠しており、ウェブブラウザはこれらの相対パスを現在のドキュメントのベースURL(この場合はgolang.org
)を基準として正しく解決します。
コアとなるコードの変更箇所
変更は doc/articles/laws_of_reflection.html
ファイルのみです。
--- a/doc/articles/laws_of_reflection.html
+++ b/doc/articles/laws_of_reflection.html
@@ -48,8 +48,8 @@ fixed sets of methods. An interface variable can store any concrete
(non-interface) value as long as that value implements the
interface\'s methods. A well-known pair of examples is
<code>io.Reader</code> and <code>io.Writer</code>, the types
-<code>Reader</code> and <code>Writer</code> from the <a href=\
-"http://golang.org/pkg/io/">io package</a>:\
+<code>Reader</code> and <code>Writer</code> from the\
+<a href=\"/pkg/io/\">io package</a>:\
</p>
\
{{code \"/doc/progs/interface.go\" `/// Reader/` `/STOP/`}}\
@@ -101,11 +101,10 @@ interfaces are closely related.\
<p><b>The representation of an interface</b></p>\
\
<p>\
-Russ Cox has written a <a href=\
-"http://research.swtch.com/2009/12/go-data-structures-interfaces.html\">\
-detailed blog post</a> about the representation of interface values\
-in Go. It\'s not necessary to repeat the full story here, but a\
-simplified summary is in order.\
+Russ Cox has written a\
+<a href=\"http://research.swtch.com/2009/12/go-data-structures-interfaces.html\">detailed blog post</a>\
+about the representation of interface values in Go. It\'s not necessary to\
+repeat the full story here, but a simplified summary is in order.\
</p>\
\
<p>\
@@ -183,9 +182,9 @@ Now we\'re ready to reflect.\
At the basic level, reflection is just a mechanism to examine the\
type and value pair stored inside an interface variable. To get\
started, there are two types we need to know about in\
-<a href=\"http://golang.org/pkg/reflect\">package reflect</a>:\
-<a href=\"http://golang.org/pkg/reflect/#Type\">Type</a> and\
-<a href=\"http://golang.org/pkg/reflect/#Value\">Value</a>. Those two types\
+<a href=\"/pkg/reflect/\">package reflect</a>:\
+<a href=\"/pkg/reflect/#Type\">Type</a> and\
+<a href=\"/pkg/reflect/#Value\">Value</a>. Those two types\
give access to the contents of an interface variable, and two\
simple functions, called <code>reflect.TypeOf</code> and\
<code>reflect.ValueOf</code>, retrieve <code>reflect.Type</code>\
@@ -211,13 +210,11 @@ type: float64\
</pre>\
\
<p>\
-You might be wondering where the interface is here, since the\
-program looks like it\'s passing the <code>float64</code>\
-variable <code>x</code>, not an interface value, to\
-<code>reflect.TypeOf</code>. But it\'s there; as <a href=\
-"http://golang.org/pkg/reflect/#Type.TypeOf\">godoc reports</a>, the\
-signature of <code>reflect.TypeOf</code> includes an empty\
-interface:\
+You might be wondering where the interface is here, since the program looks\
+like it\'s passing the <code>float64</code> variable <code>x</code>, not an\
+interface value, to <code>reflect.TypeOf</code>. But it\'s there; as\
+<a href=\"/pkg/reflect/#Type.TypeOf\">godoc reports</a>, the signature of\
+<code>reflect.TypeOf</code> includes an empty interface:\
</p>\
\
<pre>\
@@ -573,15 +570,13 @@ fields.\
</p>\
\
<p>\
-Here\'s a simple example that analyzes a struct value,\
-<code>t</code>. We create the reflection object with the address of\
-the struct because we\'ll want to modify it later. Then we set\
-<code>typeOfT</code> to its type and iterate over the fields using\
-straightforward method calls (see \
-<a href=\"http://golang.org/pkg/reflect/\">package reflect</a> for details).\
-Note that we extract the names of the fields from the struct type,\
-but the fields themselves are regular <code>reflect.Value</code>\
-objects.\
+Here\'s a simple example that analyzes a struct value, <code>t</code>. We create\
+the reflection object with the address of the struct because we\'ll want to\
+modify it later. Then we set <code>typeOfT</code> to its type and iterate over\
+the fields using straightforward method calls\
+(see <a href=\"/pkg/reflect/\">package reflect</a> for details).\
+Note that we extract the names of the fields from the struct type, but the\
+fields themselves are regular <code>reflect.Value</code> objects.\
</p>\
\
{{code \"/doc/progs/interface2.go\" `/START f8/` `/STOP/`}}\
コアとなるコードの解説
上記の差分は、doc/articles/laws_of_reflection.html
ファイル内の複数の箇所で、href
属性の値が変更されていることを示しています。
例として、最初の変更箇所を見てみましょう。
変更前:
<a href="http://golang.org/pkg/io/">io package</a>
変更後:
<a href="/pkg/io/">io package</a>
この変更は、href
属性の値からhttp://golang.org
というドメイン部分を削除し、パスを/pkg/io/
というルート相対パスに変換しています。これにより、リンクはGoの公式ウェブサイトのルートディレクトリを基準として解決されるようになります。
同様の変更が、reflect
パッケージやその内部の型、関数へのリンクに対しても適用されています。
また、このコミットでは、リンクの変更だけでなく、一部のテキストの改行やスペースの調整も行われています。これは、HTMLの整形や可読性向上のための副次的な変更であり、リンクの相対化という主要な目的とは直接関係ありませんが、コミットの差分に含まれています。例えば、Russ Cox氏のブログ記事へのリンク周辺のテキストが整形されています。
これらの変更は、HTMLドキュメントの構造や内容に影響を与えるものではなく、純粋にリンクの参照方法を改善するためのものです。
関連リンク
- Go言語公式ウェブサイト: https://golang.org/
- Go言語
reflect
パッケージドキュメント: https://golang.org/pkg/reflect/ - Go言語
io
パッケージドキュメント: https://golang.org/pkg/io/
参考にした情報源リンク
- Russ Cox氏のブログ記事「Go Data Structures: Interfaces」: http://research.swtch.com/2009/12/go-data-structures-interfaces.html
- HTML
<a>
タグ (MDN Web Docs): https://developer.mozilla.org/ja/docs/Web/HTML/Element/a - 絶対パスと相対パス (ウェブ開発の文脈): https://developer.mozilla.org/ja/docs/Learn/Common_questions/What_is_a_URL#Absolute_and_relative_URLs