About Me

我的相片
Mr. Pigg
Taipei, Taiwan
檢視我的完整簡介

星期四, 7月 31, 2008

Effective Java Chapter 8 General Programming

1. Minimize the scope of local variables
- 盡量在用到的地方才宣告
- 每個變數都要有initializer, 沒有代表你還不需要宣告
- Prefer for to while
- 讓每個method的功能盡量單純

2. Prefer for-each to for

3. Know and use the libraries
- don't reinvent the wheel
- java.lang / java.util / java.io
- java.util.concurrent

3. Avoid float and double if exact answers are required
- 用BigDecimal, int or long

4. 盡量使用primitive
- 使用boxed primitives時機: Collection keys, parameter types, reflective method invocation

5. Avoid strings where other types are more appropriate

6. 不用把String 相加

7. Refer to objects by their interfaces
- 除非是沒有interface 如value class
- or interface沒有定義要用的method
- by abstract class

8. Optimize judiciously
- 如果不清楚的話,不要亂做optimization
- 好的程式架構比performance重要

9. Naming convention

10. Prefer interface to reflection

0 意見: