名前は文字(unicode) or アンスコ始まり
キーワード25個
- yieldとかclassとかない
- chanある
nilやnewの予約語は36ぐらい
- これらは上書きできる
- 混乱するかもね (するだろ)
nil := 100
- 関数の中で宣言されたエンティティはローカル
- 外はパッケージビジブル
- さらに頭を大文字にするとパッケージを跨いで参照できる
- 名前の長さに制約は無い
- けど短かい名前を推奨
- 特にローカルでスコープの小さい奴
- camelCase使う
- HTMLみたいな略語はHtmlにしない
- escapeHTMLもしくはhtmlEscape
- var, const, type, func
- .goで名前が終るファイルにプログラム書く
- package宣言で初める
- 次にimport
func fToC(f float64) float64 {
return (f - 32) * 5 / 9
}
抜粋:: Brian W. Kernighan. “The Go Programming Language (Takashi Nishibayashi's Library)”。 iBooks.
= expression と type は省略できるよ expressionを省略すると
var i, j, k int
var name string
typeを省略すると
var b, f, s = true, 2.3, “four"
関数の中でだけ使える
Because of their brevity and flexibility, short variable declarations are used to declare and initialize the majority of local variables.
抜粋:: Brian W. Kernighan. “The Go Programming Language (Takashi Nishibayashi's Library)”。 iBooks.
少なくとも1個は新しい変数をleft sideにおく必要がある
Pointerはアドレスです
x := 1
p := &x
// 値の参照は
fmt.Println(*p)
Pointerのzero valueはnil
Pointers are key to the flag package, which uses a program’s command-line arguments to set the values of certain variables distributed throughout the program.
抜粋:: Brian W. Kernighan. “The Go Programming Language (Takashi Nishibayashi's Library)”。 iBooks.
argparseみたいなやつ
名前をつけなくていい
The lifetime of a package-level variable is the entire execution of the program.
抜粋:: Brian W. Kernighan. “The Go Programming Language (Takashi Nishibayashi's Library)”。 iBooks.
はい。
一方でlocal variableはunreachableになるまで
How does the garbage collector know that a variable’s storage can be reclaimed? The full story is much more detailed than we need here, but the basic idea is that every package-level variable, and every local variable of each currently active function, can potentially be the start or root of a path to the variable in question, following pointers and other kinds of references that ultimately lead to the variable. If no such path exists, the variable has become unreachable, so it can no longer affect the rest of the computation.
抜粋:: Brian W. Kernighan. “The Go Programming Language (Takashi Nishibayashi's Library)”。 iBooks.
マークアンドスイープっぽい事をいってる?
- スワップできる x, y = y, x 多値返却 値を捨てるにはアンダースコア、gofmtで警告がでない
- C言語のtypedef
- T.(x) で変換
- CelsiusとFharenheitの冷
- オペレーター適用時に型チェックができる C + F // error
- 型にStringメソッドを実装するとPrintlnで使われる
- 文字列結合できる?
-
Scopeはコンパイル時
-
lifetimeは実行時
-
ブロックスコープあるよ
-
変数の名前解決が書いてる
-
forは二つのブロックを作るよ、ループ本体と条件