Open6

Readable Code 雑メモ

SoraSora

セキュリティ的に変数の扱い方間違ったらあかんやつ(は特に)、その他データの扱い方間違ったらエラーになるやつは、plaintext_password (unencoded_comment)など、そのデータの形式を変数にいれる方がいい。

SoraSora

その変数の利用スコープが短い場合は、変数名が短いと良い(Goのコードでよく見るやつ)
Go書く人はベテランが多い?からこの傾向が見られんのかな?

SoraSora

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!
SoraSora

Go でも以下みたいなこと出来んのかなー。やってみよ。

MakePassword (/* pw_length = */ 12)
SoraSora

Chapter Summary: How to Handle Variables

  1. Eliminate Varialbes; Especially intermediate variables
  2. Reduce the scope of each variables; which will help readers to understand the scopes of variables
  3. Prefer Write Once Variables; like JS best practice, use const.
SoraSora

pythonでtest するときはassertではなく、assertEqual の方がエラー時の情報が多いので、assertEqualがbetter.

errror message は custom assert でカスタムできること多いから、custom assertあるか確認して使ったほうがいい