You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
문제
Magic literal이라고 부르는 문자열 혹은 숫자를 사용하여, 이해하기 어렵다.
예시
해결
Magic literal이라고 부르는 숫자 혹은 일반 문자열은 코드를 읽는 사람이 값의 의미를 모르면 그 값 자체로는 의미를 명확하게 알려주지 못합니다.
예를들어서 원의 둘레를 구하기 위해서는 반지름 * 2 * 파이를 계산해야 하는데 다음과 같이 작성되어있다고 생각해보죠
그런데 실수로 숫자를 잘못 쓸 수도 있겠죠
그러면 알아차리기가 어렵습니다. 그렇다면 상수로 선언한다면 다음과 같이 작성했겠죠.
그러면 코드를 읽는 사람에게 값이 의미 하는 바를 드러낼 수 있고, 중복되어 사용하거나 실수로 작성되는 것을 막을 수 있습니다.
See also
Beta Was this translation helpful? Give feedback.
All reactions