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

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

このコミットは、Go言語の公式仕様書である doc/go_spec.html におけるビット演算子および論理演算子の表記を、より明確で誤解の少ない表現に修正するものです。特に、&^ (bit clear / AND NOT) 演算子の説明が「and not」と記述されていた箇所を「AND NOT」と大文字で強調することで、一般的な英語の「and not」というフレーズとの混同を避けることを目的としています。

コミット

commit 1b4e37a43c2cb70d8158fd9b94fdac5485d23326
Author: Russ Cox <rsc@golang.org>
Date:   Wed Sep 12 12:05:24 2012 -0400

    spec: make bitwise operators stand out
    
    The (and not) arguably sounds like it is trying to say something - and not what?.
    
    Just an idea, won't be hurt if it gets rejected.
    
    R=gri, dsymonds, r
    CC=golang-dev
    https://golang.org/cl/6498115

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

https://github.com/golang/go/commit/1b4e37a43c2cb70d8158fd9b94fdac5485d23326

元コミット内容

    spec: make bitwise operators stand out
    
    The (and not) arguably sounds like it is trying to say something - and not what?.
    
    Just an idea, won't be hurt if it gets rejected.
    
    R=gri, dsymonds, r
    CC=golang-dev
    https://golang.org/cl/6498115

変更の背景

この変更の背景には、プログラミング言語の仕様書における記述の明確性、特に技術用語の表現に関する配慮があります。Go言語の仕様書では、ビットクリア演算子 &^ を「bit clear (and not)」と説明していました。しかし、コミットメッセージにあるように、「(and not)」という表現は、文脈によっては「〜ではなく」という一般的な英語のフレーズと誤解される可能性がありました。

プログラミング言語の仕様書は、その言語の挙動を正確かつ曖昧さなく定義する最も重要なドキュメントです。そのため、わずかな表現の揺れや誤解の余地も排除することが求められます。このコミットは、特にビット演算子のような低レベルな操作に関する記述において、その意味が明確に伝わるように、表記を改善することを目的としています。具体的には、「and not」という小文字の表現を「AND NOT」と大文字で強調することで、それが一般的な英語の接続詞ではなく、特定の論理演算(ビットごとのAND NOT)を指す専門用語であることを明確にしています。

また、コミットメッセージの「Just an idea, won't be hurt if it gets rejected.」という記述から、これは比較的小さな、しかし重要な改善提案であり、仕様書の品質向上に対する継続的な取り組みの一環であることが伺えます。

前提知識の解説

プログラミング言語の仕様書 (Language Specification)

プログラミング言語の仕様書は、その言語の構文、セマンティクス(意味論)、標準ライブラリの動作などを厳密に定義した公式ドキュメントです。開発者はこの仕様書を参照することで、言語の正確な挙動を理解し、異なるコンパイラやインタプリタ間での互換性を保証することができます。仕様書は、言語設計者、コンパイラ開発者、そして上級ユーザーにとって不可欠なものです。

ビット演算子 (Bitwise Operators)

ビット演算子は、数値の個々のビットに対して直接操作を行う演算子です。主に整数型に対して適用され、低レベルなデータ操作、フラグ管理、暗号化、ネットワークプロトコル処理などで使用されます。Go言語における主要なビット演算子には以下のようなものがあります。

  • & (AND): 両方のビットが1の場合に1を返します。
  • | (OR): どちらか一方または両方のビットが1の場合に1を返します。
  • ^ (XOR): どちらか一方のビットが1の場合に1を返します(両方が同じ場合は0)。
  • &^ (AND NOT / Bit Clear): 左オペランドのビットが1で、かつ右オペランドのビットが0の場合に1を返します。右オペランドのビットが1の場合、左オペランドの対応するビットを0にクリアします。これは A & (^B) と同等です。
  • << (Left Shift): ビットを左にシフトします。
  • >> (Right Shift): ビットを右にシフトします。

論理演算子 (Logical Operators)

論理演算子は、ブール値(真/偽)に対して操作を行う演算子です。Go言語における主要な論理演算子には以下のようなものがあります。

  • && (Logical AND): 両方のオペランドが真の場合に真を返します。
  • || (Logical OR): どちらか一方または両方のオペランドが真の場合に真を返します。
  • ! (Logical NOT): オペランドが真であれば偽を、偽であれば真を返します。

ドキュメントの明確性

技術ドキュメント、特にプログラミング言語の仕様書においては、曖昧さのない明確な表現が極めて重要です。専門用語は一貫して使用され、一般的な単語と混同されないように配慮されるべきです。大文字の使用は、特定の用語や概念を強調し、一般的な意味合いから区別するための一般的な慣習です。例えば、「AND」と「and」では、前者が論理演算子を指すことが明確になります。

技術的詳細

このコミットの技術的詳細は、HTMLドキュメント内のテキスト置換に集約されます。具体的には、Go言語の仕様書 (doc/go_spec.html) 内で、ビット演算子や論理演算子を説明する際に使用されていた小文字の「and」「or」「not」を、対応する演算子の意味を強調するために大文字の「AND」「OR」「NOT」に置き換えています。

これは、単なる表記上の変更ですが、その影響は小さくありません。プログラミング言語の仕様書は、その言語の「真実の源」であり、開発者やツールが言語の挙動を理解する際の最終的な参照点となります。したがって、そこに記述されるすべての単語は、可能な限り正確で、誤解の余地がないようにする必要があります。

特に &^ 演算子の「bit clear (and not)」という説明は、英語のネイティブスピーカーにとっても「そして、〜ではない」という一般的な否定のフレーズと受け取られる可能性がありました。これを「bit clear (AND NOT)」とすることで、「AND NOT」が特定のビット演算の概念を指す専門用語であることが視覚的にも明確になります。同様に、論理演算子 &&||! の説明においても、対応するキーワードを大文字にすることで、その技術的な意味合いを強調しています。

この変更は、HTMLの <code> タグや <pre> タグで囲まれたコード例や文法定義のセクションではなく、通常の段落テキストや説明文中の表現に適用されています。これにより、仕様書全体の可読性と正確性が向上し、特にGo言語に不慣れな読者や、英語を母国語としない読者にとっても、技術的な概念がより明確に伝わるようになります。

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

変更は doc/go_spec.html ファイルに対して行われています。

--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
 <!--{
  "Title": "The Go Programming Language Specification",
-"Subtitle": "Version of September 7, 2012",
+"Subtitle": "Version of September 12, 2012",
  "Path": "/ref/spec"
 }-->
 
@@ -2874,8 +2874,8 @@ As a consequence, statement <code>*p++</code> is the same as <code>(*p)++</code>
 <p>
 There are five precedence levels for binary operators.
 Multiplication operators bind strongest, followed by addition
-operators, comparison operators, <code>&amp;&amp;</code> (logical and),
-and finally <code>||</code> (logical or):
+operators, comparison operators, <code>&amp;&amp;</code> (logical AND),
+and finally <code>||</code> (logical OR):
 </p>
 
 <pre class="grammar">
@@ -2918,10 +2918,10 @@ to strings. All other arithmetic operators apply to integers only.\n /    quotient               integers, floats, complex values\n %    remainder              integers\n \n-&amp;    bitwise and            integers\n-|    bitwise or             integers\n-^    bitwise xor            integers\n-&amp;^   bit clear (and not)    integers\n+&amp;    bitwise AND            integers\n+|    bitwise OR             integers\n+^    bitwise XOR            integers\n+&amp;^   bit clear (AND NOT)    integers\n \n &lt;&lt;   left shift             integer &lt;&lt; unsigned integer\n &gt;&gt;   right shift            integer &gt;&gt; unsigned integer\n@@ -2981,7 +2981,7 @@ int64    -9223372036854775808\n If the divisor is zero, a <a href=\"#Run_time_panics\">run-time panic</a> occurs.\n If the dividend is positive and the divisor is a constant power of 2,\n the division may be replaced by a right shift, and computing the remainder may\n-be replaced by a bitwise \"and\" operation:\n+be replaced by a bitwise AND operation:\n </p>\n \n <pre>\n@@ -3182,9 +3182,9 @@ The right operand is evaluated conditionally.\n </p>\n \n <pre class=\"grammar\">\n-&amp;&amp;    conditional and    p &amp;&amp; q  is  \"if p then q else false\"\n-||    conditional or     p || q  is  \"if p then true else q\"\n-!     not                !p      is  \"not p\"\n+&amp;&amp;    conditional AND    p &amp;&amp; q  is  \"if p then q else false\"\n+||    conditional OR     p || q  is  \"if p then true else q\"\n+!     NOT                !p      is  \"not p\"\n </pre>\n \n \n```

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

このコミットは、Go言語の仕様書 `doc/go_spec.html` 内のテキスト表現を修正しています。

1.  **仕様書の日付更新**:
    ```diff
    -"Subtitle": "Version of September 7, 2012",
    +"Subtitle": "Version of September 12, 2012",
    ```
    コミット日に合わせて、仕様書のバージョン日付が「September 7, 2012」から「September 12, 2012」に更新されています。これはドキュメントの正確性を保つための一般的な慣行です。

2.  **論理演算子の説明の明確化**:
    ```diff
    -operators, comparison operators, <code>&amp;&amp;</code> (logical and),
    -and finally <code>||</code> (logical or):
    +operators, comparison operators, <code>&amp;&amp;</code> (logical AND),
    +and finally <code>||</code> (logical OR):
    ```
    `&&` (論理AND) と `||` (論理OR) の説明において、括弧内の「logical and」と「logical or」がそれぞれ「logical AND」と「logical OR」に修正されています。これにより、これらの単語が一般的な意味ではなく、特定の論理演算子を指すことが強調されます。

3.  **ビット演算子の説明の明確化**:
    ```diff
    -&amp;    bitwise and            integers
    -|    bitwise or             integers
    -^    bitwise xor            integers
    -&amp;^   bit clear (and not)    integers
    +&amp;    bitwise AND            integers
    +|    bitwise OR             integers
    +^    bitwise XOR            integers
    +&amp;^   bit clear (AND NOT)    integers
    ```
    ビット演算子 `&` (AND), `|` (OR), `^` (XOR), `&^` (AND NOT) の説明において、対応するキーワードが小文字から大文字に修正されています。特に `&^` の「bit clear (and not)」が「bit clear (AND NOT)」に変更された点が重要です。これにより、「and not」が一般的な英語のフレーズではなく、ビット演算の専門用語であることが明確になります。

4.  **ビット演算の例の説明の明確化**:
    ```diff
    -be replaced by a bitwise "and" operation:
    +be replaced by a bitwise AND operation:
    ```
    除算がビットシフトに、剰余がビット演算に置き換えられる可能性のある最適化の説明において、「bitwise "and" operation」が「bitwise AND operation」に修正されています。ここでも「and」を大文字にすることで、ビットごとのAND演算を指すことが明確になります。

5.  **条件付き論理演算子の説明の明確化**:
    ```diff
    -&amp;&amp;    conditional and    p &amp;&amp; q  is  "if p then q else false"
    -||    conditional or     p || q  is  "if p then true else q"
    -!     not                !p      is  "not p"
    +&amp;&amp;    conditional AND    p &amp;&amp; q  is  "if p then q else false"
    +||    conditional OR     p || q  is  "if p then true else q"
    +!     NOT                !p      is  "not p"
    ```
    条件付き論理演算子 `&&` (AND), `||` (OR), `!` (NOT) の説明において、対応するキーワードが小文字から大文字に修正されています。これにより、これらの単語が一般的な意味ではなく、特定の論理演算子を指すことが強調されます。

これらの変更はすべて、Go言語の仕様書における技術用語の明確性を高め、読者が誤解する可能性を減らすことを目的としています。

## 関連リンク

*   Go言語公式ウェブサイト: [https://go.dev/](https://go.dev/)
*   Go言語仕様書: [https://go.dev/ref/spec](https://go.dev/ref/spec)

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

*   Go言語のコミット履歴 (GitHub): [https://github.com/golang/go/commits/master](https://github.com/golang/go/commits/master)
*   Go言語のコードレビューシステム (Gerrit): [https://go.googlesource.com/go/+/refs/heads/master](https://go.googlesource.com/go/+/refs/heads/master) (コミットメッセージに記載されている `https://golang.org/cl/6498115` は、当時のGerritのURL形式です。)
*   ビット演算子に関する一般的な情報 (例: Wikipedia, MDN Web Docsなど)
*   論理演算子に関する一般的な情報 (例: Wikipedia, MDN Web Docsなど)