Skip to content

Instantly share code, notes, and snippets.

@wittyfool
Last active May 8, 2018 09:36
Show Gist options
  • Save wittyfool/199f927758458fc378ed to your computer and use it in GitHub Desktop.
Save wittyfool/199f927758458fc378ed to your computer and use it in GitHub Desktop.
ミニマリストのコーディングスタイル

ミニマリストのコーディングスタイル(Perl)

  • 寿命の短すぎる変数を使わない
# before
$filename='/foo/bar/config.txt';
open(FP, '<', $filename) || die $@;
#
# after
open(FP, '<', '/foo/bar/config.txt') || die $@;

一回しか参照されない変数って要らないんじゃないかな。

マジックナンバーをなくす? それならコメントの方が良くない?日本語でおkだし。

  • 寿命の長すぎる変数を使わない

定義した後に音沙汰なしで何百行もあとに突然出てくる変数やめよう 丁度良いのは10行から100行くらいか・・・

  • 変数も構造化する
# before
$config_width = 200;
$config_height = 100;
$config_debug = 1;
#
# after
$config = {
  display => {
    width => 200,
    height => 100,
  },
  debug => 1
};
  • 綴りのミスをどう防ぐか? $config->{wizth} とか。use strict では検知できない。 defined を毎回チェックするのは面倒

- 出力はリダイレクト

  • 未完了の出力が利用されるのを防ぐ。リネーム活用?

似たようなコマンドラインプログラムを作るときにできるだけコピーしないで対応する

  • シンボリックリンク テクニック
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment