Should I return from a function early or use an if statement?
I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why. public void SomeFunction(bool someCondition) { if (someCondition...
softwareengineering.stackexchange.com
public void SomeFunction(bool someCondition)
{
if (someCondition)
{
// Do Something
}
}
or
public void SomeFunction(bool someCondition)
{
if (!someCondition)
return;
// Do Something
}
결론은 각자 취향이다. 난 Early return 방식이 좋은 것 같다.
그리고 위 질문은 stackoverflow site 에서는 opinion-based 질문이라 허용되지 않는 질문양식이다. 그래서 위 질문글을 포스팅 했다가 강제 closed 되었다... 참고 : https://softwareengineering.stackexchange.com/help/closed-questions
stackoverflow에서 예전에는 opinion-based (취향문제) 에 관한 토론형식의 질문글도 올라왔었지만, 지금은 허용되지 않는 모양이다. 질문글 올렸는데 잘못된 질문이라고 커멘트가 달려서 방어기제로 왜 안되냐! 라고 답변했더니 내 질문글을 closed 해버렸다.ㅜㅜ
'개발 > Code review' 카테고리의 다른 글
Java "Switch vs If which is better for String comparison" (0) | 2020.07.31 |
---|---|
Code Review: Return Empty Collections Instead of Null (0) | 2020.07.27 |