Effective Go 翻訳 ~ Formatting

  • URLをコピーしました!
目次

はじめに

英語の勉強でリーディングを始めました。Go言語の勉強も兼ねてEffective Goを翻訳していければと思います。
自分の勉強用の翻訳なので、直訳かつ、訳に間違いがあるかもしれませんが、ご容赦いただければ幸いです。
もし間違いを見つけた方はコメントいただけると嬉しいです。

念のため、Effective GoのCopyrightを記載します。
コンテンツは Creative Commons Attribution 3.0 License、コードはBSD licenseとなっているため、適切に引用や翻訳すれば問題なさそうでした。

Effective Go 翻訳

Formatting

Formatting issues are the most contentious but the least consequential. People can adapt to different formatting styles but it’s better if they don’t have to, and less time is devoted to the topic if everyone adheres to the same style. The problem is how to approach this Utopia without a long prescriptive style guide.

https://golang.org/doc/effective_go#formatting

フォーマットの問題は最も論争的だがそれほど重要ではありません。人々は異なるフォーマットスタイルに適応できるが、適応する必要が無い方が良く、もし全員が同じスタイルに執着するならこのトピック(フォーマット論争)に専念する時間が少なくなります。問題は長い規範的なスタイルガイド無しでこのユートピアにアプローチする方法です。

With Go we take an unusual approach and let the machine take care of most formatting issues. The gofmt program (also available as go fmt, which operates at the package level rather than source file level) reads a Go program and emits the source in a standard style of indentation and vertical alignment, retaining and if necessary reformatting comments. If you want to know how to handle some new layout situation, run gofmt; if the answer doesn’t seem right, rearrange your program (or file a bug about gofmt), don’t work around it.

https://golang.org/doc/effective_go#formatting

Goでは、通常とは異なるアプローチを採用し、ほとんどのフォーマット問題を機械に対処させます。”gofmt”プログラム(ソースファイルレベルよりもむしろパッケージレベルとして動作する”go fmt”も利用可能) はGoプラグラムを読み込み、インデント、vertical alignmentについて標準スタイルのソースを出力し、必要に応じてコメントを保持し再フォーマットします。もしあなたがいくつかの新しいレイアウト位置について扱い方を知りたいなら、”gofmt”を実行してください。もし回答が正しくなさそうであれば、回避するのではなく、プログラムを再構成して(もしくは”gofmt”についてバグを報告して)ください。

type T struct {
    name string // name of the object
    value int // its value
}

gofmt will line up the columns:

https://golang.org/doc/effective_go#formatting

“gofmt”は列を並べます。

type T struct {
    name    string // name of the object
    value   int    // its value
}

All Go code in the standard packages has been formatted with gofmt.

標準パッケージに含まれる全てのGoコードは”gofmt”でフォーマットされています。

Some formatting details remain. Very briefly:

Indentation

 We use tabs for indentation and gofmt emits them by default. Use spaces only if you must.

Line length

 Go has no line length limit. Don’t worry about overflowing a punched card. If a line feels too long, wrap it and indent with an extra tab.

Parentheses

 Go needs fewer parentheses than C and Java: control structures (ifforswitch) do not have parentheses in their syntax. Also, the operator precedence hierarchy is shorter and clearer, so

  x<<8 + y<<16

 means what the spacing implies, unlike in the other languages.

https://golang.org/doc/effective_go#formatting

一部のフォーマットの詳細は残っています。とても簡潔に:
インデント
 私たちはインデントにタブを使用し、”gofmt”はデフォルトでそれらを出力します。必要な時のみスペースを使用してください。
行の長さ
 Goは行の長さに制限がありません。パンチカードが溢れることについて心配は要りません。もし行がとても長いと感じる場合、それを折り返し、追加のタブでインデントします。
括弧
 GoはCやJavaより括弧が少なくて済みます。制御構造(”if”, “for”, “switch”)はシンタックスに括弧を持ちません。また、オペレーターの優先順位階層は短く明確です。x<<8 + y<<16は、他の言語とは異なり、スペースが暗示することを意味します。

文法メモ

be devoted to + 名詞、devote oneself to + 名詞 (〜に専念する)

less time is devoted to the topic少ない時間がこのトピックに専念する
She devoted herself to cancer research.彼女はガンの研究に専念した。
My dad is devoted to my family.私のパパは家族想いだ。

adhere to + 名詞 (〔信仰・考え・計画などに〕執着[固執]する、〔…を〕支持[信奉]する)

everyone adheres to the same style全員が同じスタイルに固執する
We must adhere to the regulations by the company.私たちは会社によって決められた規則に従わなければならない。
I don’t adhere to any organized religion.私はいかなる宗教も支持していません。

【使役動詞】let + A[目的語] + B[原型不定詞] (AにBさせる、AがBすることを許可する)

We let the machine take care of most formatting issues.私たちは機械にほとんどのフォーマット問題を対処させる。
Ann’s father didn’t let her go on a date with me.アンのパパはアンが私とデートに行くことを許さなかった。
The CEO won’t let any journalist enter his company.社長は会社に一切記者を入れない。

take care of + 人 (〜の世話をする)、take care of + 物,事 (〜を対処する)

the machine takes care of most formatting issues機械がほとんどのフォーマット問題を対処する
Take care of yourself.お体をお大事に
I’ll take care of buying the wine for the party.パーティー用のワイン購入を引き受けよう

A rather than B (BよりむしろA)

the package level rather than source file levelソースファイルレベルよりむしろパッケージレベル
He likes coffee rather than tea.彼は紅茶よりコーヒーが好きだ。
I would rather ride the train than the bus.私はバスより電車に乗りたい。

If only ~ (〜でさえあれば)、only If ~ (〜の場合に限り)

If only you could get well!あなたが元気になりさえすれば!
If only it had snowed more…雪がもっと降ってさえいれば…
Ice cream is half price, only if you are a child.子供に限り、アイスクリームは半額です。

単語

contentious・〈人が〉争いを好む,議論好きな
・〈問題など〉議論[異論]のある
consequential・重大な
〈人が〉もったいぶった、尊大な
・結果として起こる、当然な、必然の
prescriptive・規定する、指令を与える
・【文法】規範的な
retain〈…を〉保つ、保持する
〈…を〉忘れないでいる、記憶している
emit・出す、放射する、発する、発行する、出力する
parenthesis・括弧
precedence・優先順位

Effective Go 他セクションの翻訳

参考

devoteの使い方
take care of の使い方
letの使い方
rather than の使い方

よかったらシェアしてね!
  • URLをコピーしました!

コメント

コメントする

CAPTCHA


目次