[インデックス 1353] ファイルの概要
このコミットは、Go言語の仕様書である doc/go_spec.txt
の内容を更新するものです。具体的には、Go言語の「Introduction(導入)」セクションを新たに追加し、既存の「Contents(目次)」セクションを更新し、以前のドキュメントから残っていた不要なテキストを削除しています。この変更は言語仕様そのものには影響を与えず、ドキュメントの構成と説明の改善に焦点を当てています。
コミット
commit 6715358652252706120616172752bd1e1e46af6a
Author: Robert Griesemer <gri@golang.org>
Date: Tue Dec 16 14:45:09 2008 -0800
- Add introduction section (1 page), essentially a condensed form
of an earlier intro.
- Updated contents section.
- Removed left-over text from earlier documents.
No spec changes.
R=r
DELTA=379 (147 added, 227 deleted, 5 changed)
OCL=21312
CL=21331
GitHub上でのコミットページへのリンク
https://github.com/golang/go/commit/6715358652252706120616172752bd1e1e46af6a
元コミット内容
- Add introduction section (1 page), essentially a condensed form
of an earlier intro.
- Updated contents section.
- Removed left-over text from earlier documents.
No spec changes.
変更の背景
このコミットは、Go言語の初期開発段階において、その言語仕様書(doc/go_spec.txt
)の構成と可読性を向上させるために行われました。Go言語は2007年末にGoogleで設計が始まり、2009年にオープンソースとして公開されました。このコミットが行われた2008年12月は、Go言語がまだ活発に設計・開発されていた時期にあたります。
当時の仕様書は、言語の進化に合わせて頻繁に更新されており、このコミットは特に、言語の全体像を簡潔に説明する「Introduction」セクションを導入することで、読者がGo言語の主要な設計原則や特徴を素早く理解できるようにすることを目的としています。また、古いドキュメントからの残骸を削除することで、仕様書の整理とクリーンアップも同時に行われています。コミットメッセージにある「No spec changes.」という記述は、この変更が言語の機能や振る舞い自体を変更するものではなく、あくまでドキュメントの改善であることを明確に示しています。
前提知識の解説
- Go言語仕様書 (
doc/go_spec.txt
): Go言語の公式な仕様を記述したドキュメントです。言語の構文、セマンティクス、組み込み型、パッケージ、関数、並行処理モデルなど、Go言語のあらゆる側面が詳細に定義されています。開発者やコンパイラ、ツール開発者がGo言語の正確な振る舞いを理解するための主要な情報源となります。 - 言語設計の初期段階: 新しいプログラミング言語が設計される初期段階では、その仕様書も頻繁に改訂されます。この時期には、言語のコンセプトが固まり、その設計思想や主要な特徴をまとめた導入部分が特に重要になります。
- Markdown/テキストベースのドキュメント:
doc/go_spec.txt
はプレーンテキストファイルであり、当時のGo言語のドキュメントはMarkdownのような軽量マークアップ言語に近い形式で記述されていました。これは、バージョン管理システムでの変更履歴の追跡が容易であり、シンプルなツールで閲覧・編集できる利点があります。
技術的詳細
このコミットは、doc/go_spec.txt
ファイルに対して以下の具体的な変更を加えています。
-
Introductionセクションの追加:
- Go言語がC++の代替として意図された新しいシステムプログラミング言語であること、サーバーや分散システムのようなコンパイルされたプログラムのための生産的で効率的なプログラミング環境を提供することを目的としていることが述べられています。
- Guiding principles(設計原則):
- 非常に高速なコンパイル、瞬時のインクリメンタルコンパイル
- 強い型付け
- 手続き型
- 繰り返しを避けた簡潔な構文
- 少ない、直交的で一般的な概念
- スレッドとプロセス間通信のサポート
- ガベージコレクション
- Goで書かれたコンテナライブラリ
- 他のコンパイル言語に匹敵する効率的なコード といった点が挙げられています。
- Program structure(プログラム構造):パッケージ、ソースファイル、
main
パッケージとmain
関数、init
関数、分離コンパイルの概念が説明されています。 - Modularity, identifiers and scopes(モジュール性、識別子、スコープ):パッケージ内の識別子の宣言、スコープ規則、エクスポートの概念が導入されています。
- Typing, polymorphism, and object-orientation(型付け、多態性、オブジェクト指向):Goが強い型付け言語であること、インターフェース型によるオブジェクト指向のサポート、クラスや継承の明示的な概念がないこと、型パラメータやテンプレートがない代わりにインターフェース型によるコンテナの実装が説明されています。
- Pointers and garbage collection(ポインタとガベージコレクション):変数の自動割り当てとヒープ割り当て、ポインタの使用、自動的なメモリ解放(ガベージコレクション)、ポインタ演算がないことが述べられています。
- Values and references(値と参照):すべてのオブジェクトが値セマンティクスを持つこと、参照を渡すには明示的にポインタを渡す必要があること(配列の例でC言語との違いを強調)が説明されています。
- Multithreading and channels(マルチスレッドとチャネル):Goがマルチスレッドプログラミングを直接サポートし、チャネルとその関連言語サポートを通じて通信と同期が提供されることが述べられています。
-
Contentsセクションの更新:
- 新しく追加された「Introduction」セクションのサブ項目(Guiding principles, Program structureなど)が目次に追加され、仕様書の構造がより詳細に反映されています。
- 既存の項目(例: Function declarations以下のMethod declarationsなど)のインデントが修正され、階層構造がより明確になっています。
-
不要なテキストの削除:
- 以前のドキュメントから残っていた、重複したり古くなったりした「Guiding principles」「Program structure」「Modularity, identifiers and scopes」「Typing, polymorphism, and object-orientation」「Pointers and garbage collection」「Multithreading and channels」「Values and references」などのセクションが、新しい簡潔な「Introduction」セクションに置き換えられる形で削除されています。これにより、ドキュメント全体の冗長性が排除され、一貫性が保たれています。
この変更は、Go言語の設計思想と主要な特徴を、仕様書の冒頭で簡潔かつ包括的に提示することを可能にし、読者が言語の全体像を把握しやすくなるという点で、ドキュメントの品質を大きく向上させています。
コアとなるコードの変更箇所
変更はすべて doc/go_spec.txt
ファイルに対して行われています。
--- a/doc/go_spec.txt
+++ b/doc/go_spec.txt
@@ -3,9 +3,9 @@ The Go Programming Language Specification (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson
-----
(December 16, 2008)
+----
This document is a semi-formal specification of the Go systems
programming language.
@@ -15,6 +15,7 @@ This document is not ready for external review, it is under active development.
Any part may change substantially as design progresses.\n </font>\n \n+----\n \n <!--\n Timeline (9/5/08):\n@@ -128,6 +129,13 @@ Contents\n ----\n \n \tIntroduction\n+\t\tGuiding principles\n+\t\tProgram structure\n+\t\tModularity, identifiers and scopes\n+\t\tTyping, polymorphism, and object-orientation\n+\t\tPointers and garbage collection\n+\t\tValues and references\n+\t\tMultithreading and channels\n \n \tNotation\n \n@@ -207,11 +215,11 @@ Contents\n \t\tGoto statements\n \n \tFunction declarations\n-\tMethod declarations\n-\tPredeclared functions\n-\t\tLength and capacity\n-\t\tConversions\n-\t\tAllocation\n+\t\tMethod declarations\n+\t\tPredeclared functions\n+\t\t\tLength and capacity\n+\t\t\tConversions\n+\t\t\tAllocation\n \n \tPackages\n \n@@ -223,6 +231,129 @@ Contents\n Introduction\n ----\n \n+Go is a new systems programming language intended as an alternative to C++ at\n+Google. Its main purpose is to provide a productive and efficient programming\n+environment for compiled programs such as servers and distributed systems.\n+\n+\n+Guiding principles\n+----\n+\n+The design of Go is motivated by the following goals (in no particular order):\n+\n+- very fast compilation, instantaneous incremental compilation\n+- strongly typed\n+- procedural\n+- concise syntax avoiding repetition\n+- few, orthogonal, and general concepts\n+- support for threading and interprocess communication\n+- garbage collection\n+- container library written in Go\n+- efficient code, comparable to other compiled languages\n+\n+\n+Program structure\n+----\n+\n+A Go program consists of a number of ``packages\'\'.\n+\n+A package is built from one or more source files, each of which consists\n+of a package specifier followed by declarations. There are no statements at\n+the top level of a file.\n+\n+By convention, the package called \"main\" is the starting point for execution.\n+It contains a function, also called \"main\", that is the first function invoked\n+by the run time system after initialization (if a source file within the program\n+contains a function \"init()\", that function will be executed before \"main.main()\"\n+is called).\n+\n+Source files can be compiled separately (without the source code of packages\n+they depend on), but not independently (the compiler does check dependencies\n+by consulting the symbol information in compiled packages).\n+\n+\n+Modularity, identifiers and scopes\n+----\n+\n+A package is a collection of import, constant, type, variable, and function\n+declarations. Each declaration binds an ``identifier\'\' with a program entity\n+(such as a variable).\n+\n+In particular, all identifiers in a package are either declared explicitly\n+within the package, arise from an import statement, or belong to a small set\n+of predeclared identifiers (such as \"string\").\n+\n+Scoping follows the usual rules: The scope of an identifier declared within\n+a ``block\'\' generally extends from the declaration of the identifier to the\n+end of the block. An identifier shadows identifiers with the same name declared\n+in outer scopes. Within a scope, an identifier can be declared at most once.\n+\n+A package may mark explicitly declared identifiers for ``export\'\' to make them\n+visible to other source files in the same package, or to other packages.\n+\n+\n+Typing, polymorphism, and object-orientation\n+----\n+\n+Go programs are strongly typed. Certain variables may be polymorphic.\n+The language provides mechanisms to make use of such polymorphic variables\n+type-safe.\n+\n+Object-oriented programming is supported by interface types.\n+Different interface types are independent of each\n+other and no explicit hierarchy is required (such as single or\n+multiple inheritance explicitly specified through respective type\n+declarations). Interface types only define a set of methods that a\n+corresponding implementation must provide. Thus interface and\n+implementation are strictly separated.\n+\n+An interface is implemented by associating methods with types. If a type\n+defines all methods of an interface, it implements that interface and thus\n+can be used where that interface is required. Unless used through a variable\n+of interface type, methods can always be statically bound (they are not\n+``virtual\'\'), and invoking them incurs no extra run-time overhead compared\n+to ordinary functions.\n+\n+Go has no explicit notion of classes, sub-classes, or inheritance.\n+These concepts are trivially modeled in Go through the use of\n+functions, structures, embedding of types, associated methods, and interfaces.\n+\n+Go has no explicit notion of type parameters or templates. Instead,\n+containers (such as stacks, lists, etc.) are implemented through the\n+use of abstract operations on interface types.\n+\n+\n+Pointers and garbage collection\n+----\n+\n+Variables may be allocated automatically (when entering the scope of\n+the variable) or explicitly on the heap. Pointers are used to refer\n+to heap-allocated variables. Pointers may also be used to point to\n+any other variable; such a pointer is obtained by \"taking the\n+address\" of that variable. Variables are automatically reclaimed when\n+they are no longer accessible. There is no pointer arithmetic in Go.\n+\n+\n+Values and references\n+----\n+\n+All objects have value semantics, but their contents may be accessed\n+through different pointers referring to the same object.\n+For example, when calling a function with an array, the array is\n+passed by value, possibly by making a copy. To pass a reference,\n+one must explicitly pass a pointer to the array.\n+\n+\n+Multithreading and channels\n+----\n+\n+Go supports multithreaded programming directly. A function may\n+be invoked as a parallel thread of execution. Communication and\n+synchronization are provided through channels and their associated\n+language support.\n+\n+\n+----\n \n Notation\n ----\n@@ -274,6 +405,7 @@ A production may be referenced from various places in this document\n but is usually defined close to its first use. Productions and code\n examples are indented.\n \n+----\n \n Source code representation\n ----\n@@ -315,6 +447,7 @@ Letters and digits\n \n All non-ASCII code points are considered letters; digits are always ASCII.\n \n+----\n \n Vocabulary\n ----\n@@ -538,6 +671,8 @@ The following words are reserved and must not be used as identifiers:\n \tcontinue for import return var\n \n \n+----\n+\n Declarations and scope rules\n ----\n \n@@ -921,6 +1056,7 @@ export directive.\n \texport sin, cos\n \texport math.abs\n \n+----\n \n Types\n ----\n@@ -1583,6 +1719,8 @@ As an example, \"T0\" and \"T1\" are equal but not identical because they have\n different declarations.\n \n \n+----\n+\n Expressions\n ----\n \n@@ -2362,6 +2500,8 @@ TODO: Complete this list as needed.\n Constant expressions can be evaluated at compile time.\n \n \n+----\n+\n Statements\n ----\n \n@@ -2884,6 +3024,8 @@ clause of the switch statement.\n \tFallthroughStat = \"fallthrough\" .\n \n \n+----\n+\n Function declarations\n ----\n \n@@ -3069,6 +3211,8 @@ into a faster internal call that doesn\'t do slicing).\n -->\n \n \n+----\n+\n Packages\n ----\n \n@@ -3168,6 +3312,8 @@ Here is a complete example Go package that implements a concurrent prime sieve:\n \t}\n \n \n+----\n+\n Program initialization and execution\n ----\n \n@@ -3233,229 +3379,3 @@ When main.main() returns, the program exits.\n \n TODO: is there a way to override the default for package main or the\n default for the function name main.main?\n-\n-\n-<!--\n-----\n-----\n-UNUSED PARTS OF OLD DOCUMENT go_lang.txt - KEEP AROUND UNTIL NOT NEEDED ANYMORE\n-----\n-\n-Guiding principles\n-----\n-\n-Go is a new systems programming language intended as an alternative to C++ at\n-Google. Its main purpose is to provide a productive and efficient programming\n-environment for compiled programs such as servers and distributed systems.\n-\n-The design is motivated by the following guidelines:\n-\n-- very fast compilation (1MLOC/s stretch goal); instantaneous incremental compilation\n-- procedural\n-- strongly typed\n-- concise syntax avoiding repetition\n-- few, orthogonal, and general concepts\n-- support for threading and interprocess communication\n-- garbage collection\n-- container library written in Go\n-- reasonably efficient (C ballpark)\n-\n-The language should be strong enough that the compiler and run time can be\n-written in itself.\n-\n-\n-Program structure\n-----\n-\n-A Go program consists of a number of ``packages\'\'.\n-\n-A package is built from one or more source files, each of which consists\n-of a package specifier followed by import declarations followed by other\n-declarations. There are no statements at the top level of a file.\n-\n-By convention, one package, by default called main, is the starting point for\n-execution. It contains a function, also called main, that is the first function\n-invoked by the run time system.\n-\n-If a source file within the program\n-contains a function init(), that function will be executed\n-before main.main() is called.\n-\n-Source files can be compiled separately (without the source\n-code of packages they depend on), but not independently (the compiler does\n-check dependencies by consulting the symbol information in compiled packages).\n-\n-\n-Modularity, identifiers and scopes\n-----\n-\n-A package is a collection of import, constant, type, variable, and function\n-declarations. Each declaration associates an ``identifier\'\' with a program\n-entity (such as a type).\n-\n-In particular, all identifiers in a package are either\n-declared explicitly within the package, arise from an import statement,\n-or belong to a small set of predefined identifiers (such as \"int32\").\n-\n-A package may make explicitly declared identifiers visible to other\n-packages by marking them as exported; there is no ``header file\'\'.\n-Imported identifiers cannot be re-exported.\n-\n-Scoping is essentially the same as in C: The scope of an identifier declared\n-within a ``block\'\' extends from the declaration of the identifier (that is, the\n-position immediately after the identifier) to the end of the block. An identifier\n-shadows identifiers with the same name declared in outer scopes. Within a\n-block, a particular identifier must be declared at most once.\n-\n-\n-Typing, polymorphism, and object-orientation\n-----\n-\n-Go programs are strongly typed. Certain values can also be\n-polymorphic. The language provides mechanisms to make use of such\n-polymorphic values type-safe.\n-\n-Interface types provide the mechanisms to support object-oriented\n-programming. Different interface types are independent of each\n-other and no explicit hierarchy is required (such as single or\n-multiple inheritance explicitly specified through respective type\n-declarations). Interface types only define a set of methods that a\n-corresponding implementation must provide. Thus interface and\n-implementation are strictly separated.\n-\n-An interface is implemented by associating methods with types.\n-If a type defines all methods of an interface, it\n-implements that interface and thus can be used where that interface is\n-required. Unless used through a variable of interface type, methods\n-can always be statically bound (they are not ``virtual\'\'), and incur no\n-run-time overhead compared to an ordinary function.\n-\n-[OLD\n-Interface types, building on structures with methods, provide\n-the mechanisms to support object-oriented programming.\n-Different interface types are independent of each\n-other and no explicit hierarchy is required (such as single or\n-multiple inheritance explicitly specified through respective type\n-declarations). Interface types only define a set of methods that a\n-corresponding implementation must provide. Thus interface and\n-implementation are strictly separated.\n-\n-An interface is implemented by associating methods with\n-structures. If a structure implements all methods of an interface, it\n-implements that interface and thus can be used where that interface is\n-required. Unless used through a variable of interface type, methods\n-can always be statically bound (they are not ``virtual\'\'), and incur no\n-run-time overhead compared to an ordinary function.\n-END]\n-\n-Go has no explicit notion of classes, sub-classes, or inheritance.\n-These concepts are trivially modeled in Go through the use of\n-functions, structures, associated methods, and interfaces.\n-\n-Go has no explicit notion of type parameters or templates. Instead,\n-containers (such as stacks, lists, etc.) are implemented through the\n-use of abstract operations on interface types or polymorphic values.\n-\n-\n-Pointers and garbage collection\n-----\n-\n-Variables may be allocated automatically (when entering the scope of\n-the variable) or explicitly on the heap. Pointers are used to refer\n-to heap-allocated variables. Pointers may also be used to point to\n-any other variable; such a pointer is obtained by \"taking the\n-address\" of that variable. Variables are automatically reclaimed when\n-they are no longer accessible. There is no pointer arithmetic in Go.\n-\n-\n-Multithreading and channels\n-----\n-\n-Go supports multithreaded programming directly. A function may\n-be invoked as a parallel thread of execution. Communication and\n-synchronization are provided through channels and their associated\n-language support.\n-\n-\n-Values and references\n-----\n-\n-All objects have value semantics, but their contents may be accessed\n-through different pointers referring to the same object.\n-For example, when calling a function with an array, the array is\n-passed by value, possibly by making a copy. To pass a reference,\n-one must explicitly pass a pointer to the array. For arrays in\n-particular, this is different from C.\n-\n-There is also a built-in string type, which represents immutable\n-strings of bytes.\n-\n-\n-Interface of a type\n-----\n-\n-The interface of a type is defined to be the unordered set of methods\n-associated with that type. Methods are defined in a later section;\n-they are functions bound to a type.\n-\n-\n-[OLD\n-It is legal to assign a pointer to a struct to a variable of\n-compatible interface type. It is legal to assign an interface\n-variable to any struct pointer variable but if the struct type is\n-incompatible the result will be nil.\n-END]\n-\n-\n-[OLD\n-The polymorphic \"any\" type\n-----\n-\n-Given a variable of type \"any\", one can store any value into it by\n-plain assignment or implicitly, such as through a function parameter\n-or channel operation. Given an \"any\" variable v storing an underlying\n-value of type T, one may:\n-\n-\t- copy v\'s value to another variable of type \"any\"\n-\t- extract the stored value by an explicit conversion operation T(v)\n-\t- copy v\'s value to a variable of type T\n-\t\n-Attempts to convert/extract to an incompatible type will yield nil.\n-\n-No other operations are defined (yet).\n-\n-Note that type\n-\tinterface {}\n-is a special case that can match any struct type, while type\n-\tany\n-can match any type at all, including basic types, arrays, etc.\n-\n-TODO: details about reflection\n-END]\n-\n-\n-[OLD\n-The nil value\n-----\n-\n-The predeclared constant\n-\n-\tnil\n-\n-represents the ``zero\'\' value for a pointer type or interface type.\n-\n-The only operations allowed for nil are to assign it to a pointer or\n-interface variable and to compare it for equality or inequality with a\n-pointer or interface value.\n-\n-\tvar p *int;\n-\tif p != nil {\n-\t\tprint(p)\n-\t} else {\n-\t\tprint(\"p points nowhere\")\n-\t}\n-\n-By default, pointers are initialized to nil.\n-\n-TODO: This needs to be revisited.\n--->
コアとなるコードの解説
このコミットの主要な変更は、Go言語の仕様書 doc/go_spec.txt
に、言語の設計思想と主要な特徴をまとめた「Introduction」セクションを導入した点です。
具体的には、以下の点が重要です。
-
新しい「Introduction」セクションの追加:
- Go言語がC++の代替として、サーバーや分散システム向けの効率的なプログラミング環境を提供することを目指しているという、言語の根本的な目的が明記されました。
- 「Guiding principles」として、高速なコンパイル、強い型付け、手続き型、簡潔な構文、直交的な概念、並行処理のサポート、ガベージコレクション、効率的なコードといった、Go言語の設計を導く重要な原則が列挙されました。これらはGo言語がなぜ現在の形になったのかを理解する上で非常に重要な情報です。
- 「Program structure」では、パッケージ、ソースファイル、
main
パッケージとmain
関数、init
関数の役割、そして分離コンパイルの概念が説明され、Goプログラムの基本的な構成が明確にされました。 - 「Modularity, identifiers and scopes」では、パッケージ内の識別子の宣言とスコープ規則、エクスポートの仕組みが導入され、Go言語におけるコードの組織化と可視性のルールが示されました。
- 「Typing, polymorphism, and object-orientation」では、Goが強い型付け言語であること、インターフェース型によるオブジェクト指向のサポート、そしてクラスや継承といった概念がGoではどのように扱われるか(明示的なクラスや継承はないが、関数、構造体、埋め込み、メソッド、インターフェースを通じてモデル化される)が説明されました。特に、Goのインターフェースが「型パラメータやテンプレート」の代替としてコンテナの実装に利用されるという初期の設計思想が示されています。
- 「Pointers and garbage collection」では、Goにおけるポインタの利用方法(ポインタ演算がないこと)と、ガベージコレクションによる自動的なメモリ管理が説明されました。
- 「Values and references」では、Goのオブジェクトが値セマンティクスを持つこと、そして参照渡しが必要な場合には明示的にポインタを渡す必要があることが強調されました。これはC言語などとは異なるGoの重要な特徴です。
- 「Multithreading and channels」では、Goがゴルーチンとチャネルを通じて並行処理を直接サポートしていることが述べられ、Goの並行処理モデルの基礎が示されました。
-
目次 (
Contents
) の更新:- 新しく追加された「Introduction」セクションのサブ項目が目次に追加され、仕様書の論理的な構造がより明確になりました。
- 既存の「Function declarations」以下の項目(「Method declarations」「Predeclared functions」など)のインデントが修正され、視覚的な階層構造が改善されました。
-
古い、不要なテキストの削除:
- 以前のドキュメントに存在した、新しい「Introduction」セクションの内容と重複したり、古くなったりした詳細な説明(例:
UNUSED PARTS OF OLD DOCUMENT go_lang.txt - KEEP AROUND UNTIL NOT NEEDED ANYMORE
とコメントされていた部分)が削除されました。これにより、仕様書全体の整合性が高まり、読者が混乱する可能性が低減されました。
- 以前のドキュメントに存在した、新しい「Introduction」セクションの内容と重複したり、古くなったりした詳細な説明(例:
このコミットは、Go言語の仕様書が、単なる技術的なリファレンスとしてだけでなく、言語の設計哲学と主要な特徴を伝えるための重要なドキュメントとしての役割を果たす上で、大きな一歩となりました。
関連リンク
参考にした情報源リンク
- この解説は、提供されたコミット情報と
doc/go_spec.txt
の差分内容に基づいて生成されました。追加の外部情報源は直接参照していません。