CodingHabit

Guard Clause

AsCE_hyunseung 2018. 11. 6. 14:30

Guard Clause

- 로직의 시작 지점 제일 상단에 방어 코드를 걸어서 하단 로직을 타게 하지 않는 것

- ex) 1->2


1.

1
2
3
4
5
void initialize() {
  if (!isInitialized()) {
    ...
  }
}
cs


2.

1
2
3
4
5
void initialize() {
  if (isInitialized()){
    return;
}
  ...
}
cs