- Notifications
You must be signed in to change notification settings - Fork173
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
❓ 질문작성한 함수들을 뒤돌아보면 크게 2가지 모습을 띠고 있기에, 고민이 시작되었습니다.
1️⃣ 조건마다 바로 returnfunctionexample(){if(condition)returntrue;elsereturnfalse;} 장점
단점
2️⃣ 마지막에 returnfunctionexample(){letresult=false;if(condition)result=true;elseresult=false;returnresult;} 장점
단점
각자 가지고 있는 장점이 뚜렷하고 케이스가 대비되기 때문에 '둘 중 어떤 방법을 사용해야 한다' 이전에 '상황에 따라 둘 다 사용하면 된다'는 담론 또한 가능합니다. 만약 둘 다 사용되는 방향으로 간다면함수가 간단할 땐 1안,복잡하거나 clean-up 처리가 필요할 땐 2안을 선택하도록 선택 가이드를 잡아두게 될 것 같습니다. |
Clean code 관점에서 함수의 return문 위치는? 조건 발생 시점 95% 마지막에 하나만 4% 24 votes· |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 0 comments
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment