알고보면 당연한 내용인데 코딩하다가 자주 하는 실수, Java Code Conventions 내용중에 있군요.
써놓고나면 덜 실수하려나...
출처 : http://java.sun.com/docs/codeconv/
Miscellaneous Practices
10.5.1 Parentheses
It is generally a good idea to use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems. Even if the operator precedence seems clear to you, it might not be to others-you shouldn't assume that other programmers know precedence as well as you do.
if (a == b && c == d) // AVOID!
if ((a == b) && (c == d)) // RIGHT
10.5.2 Returning Values
Try to make the structure of your program match the intent. Example:
if (booleanExpression) {
return true;
} else {
return false;
}
return booleanExpression;
if (condition) {
return x;
}
return y;
return (condition ? x : y);
10.5.3 Expressions before `?' in the Conditional Operator
If an expression containing a binary operator appears before the ?
in the ternary ?:
operator, it should be parenthesized. Example:
(x >= 0) ? x : -x;
10.5.4 Special Comments
Use XXX
in a comment to flag something that is bogus but works. Use FIXME
to flag something that is bogus and broken.
'나만의 작업 > Java' 카테고리의 다른 글
[Effective Java] 9. equals 메소드를 오버라이드 할 땐 hashCode 메소드도 항상 오버라이드 하자. (0) | 2009.09.28 |
---|---|
[Effective Java] 8. equals 메소드를 오버라이딩 할 때는 보편적 계약을 따르자. (4) | 2009.09.24 |
[Effective Java] 5. 불필요한 객체 생성을 피하자 (4) | 2009.09.23 |
[Effective Java] 4. private 생성자를 사용해서 인스턴스 생성을 못하게 하자 (0) | 2009.09.17 |
Eclipse Galileo에 어떤 프로젝트가 있을까? (2) | 2009.08.26 |
[Effective Java] 3. private 생성자나 enum 타입을 사용해서 싱글톤의 특성을 유지하자. (3) | 2009.08.26 |
[Effective Java] 생성자의 매개변수가 많을 때는 빌더(builder)를 고려하자. (3) | 2009.07.31 |
[Java] 자바 코딩하다가 실수하는 부분들 (8) | 2008.03.03 |
[java] java.util.Properties 클래스 (4) | 2007.05.10 |
이런 건 알면서도 경험이 없으면 지나치기 쉬운 부분이네요..
멋져요.
길님 멋져요~
precedence 문제는 참.. 사용할수록 골치가 아파지더라구요 ㅎ
좋은글 잘보고 갑니다 ^^
들러주셔서 감사해요~^_^
10.5.2 보고 '3항 연산자는 condition 구하는 수식이 복잡하면 코드가 더 난잡해지는데...' 라고 생각하고 적을라치니까 10.5.3에 괄호로 묶으라고 나오네요. ㅎㅎ;;
축약해서 라인 수를 줄이는 게 가독성에 나쁜 경우도 있는 거니까... 상황 따라 판단해야 할 것들도 있을 것 같아요. ^^
잘 봤어요~
^^;; 코드도 사람이 짜는거지만 결국 코드를 사람이 읽는거니깐..^^사람이 이해되게 짜야겠죠~^^
대부분의 return 문에선 장황한 if else 보다 ? : 가 더 눈에 잘 들어오죠~
아님 말구=3=3=3=33
if-else보다 삼항연산자가 더 눈에 잘 들어오는거 같아요~