Open6
Readable Code 雑メモ
セキュリティ的に変数の扱い方間違ったらあかんやつ(は特に)、その他データの扱い方間違ったらエラーになるやつは、plaintext_password (unencoded_comment)など、そのデータの形式を変数にいれる方がいい。
その変数の利用スコープが短い場合は、変数名が短いと良い(Goのコードでよく見るやつ)
Go書く人はベテランが多い?からこの傾向が見られんのかな?
Comment the Flaws(欠陥) in Your Code
It is efficient to comment flaws like,
Marker | Typical meaning |
---|---|
TODO: | Stuff I have not yet got started |
FIXME: | Known-broken code right here |
HACK: | Admittedly inelegant solution to a problem |
XXX: | Danger! magor problem right here! |
Go でも以下みたいなこと出来んのかなー。やってみよ。
MakePassword (/* pw_length = */ 12)
Chapter Summary: How to Handle Variables
- Eliminate Varialbes; Especially intermediate variables
- Reduce the scope of each variables; which will help readers to understand the scopes of variables
- Prefer Write Once Variables; like JS best practice, use const.
pythonでtest するときはassertではなく、assertEqual の方がエラー時の情報が多いので、assertEqualがbetter.
errror message は custom assert でカスタムできること多いから、custom assertあるか確認して使ったほうがいい