LoginSignup
1
1

More than 5 years have passed since last update.

変数名/関数名の命名規則とガード

Posted at

命名規則

・変数名 … 基本的に名詞からはじまる
  ∟真偽値 … 問いかけ/可能形
    男(male)か否か
     boolean male = true; // BAD
     boolean isMale = true; // GOOD
    書き込まれたか?
     boolean isWrited = true;
  ∟それ以外 … 名詞から

・関数名 … 動詞からはじまる

ガード

それ以降もう処理する必要のない条件分岐なら returnで強制終了させる。
return 2つの効果
 ∟値を返す。
 ∟処理をそこで終わらせる。

java
void xxxx() {
  if (this.isLocked == true) {
    System.out.println("ロックがうんぬん");
  } else {
    ...
    ..
    ...
  }
}
void xxx() {
  if (this.isLocked == true) {
    System.out.println("ロックがうんぬん");
    return;
  }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1