ブール値の命名規則:is、has、can、should

3 分で読了

ブール値の名前はYes/Noの質問として読めるべきです。標準的な4つの接頭辞はishascanshouldです。

接頭辞ガイド

接頭辞用途
is状態・条件isActive, isLoading, isValid
has所有・存在hasPermission, hasChildren
can能力・可否canEdit, canDelete
should推奨・期待shouldRedirect, shouldRetry

アンチパターン

  • flag — 何のフラグ?
  • status — 文字列かもしれず、ブール値か不明確
  • check — 変数ではなく関数に聞こえる
  • 二重否定: isNotDisabledisEnabledを使う

変換

JSにはcamelCase、Pythonにはsnake_caseハブはこちら