2015年10月18日 星期日

Java coding style

Here are some tricks I've learned from the code review / pair with my friend yesterday.

1. Use fully qualify name name to access static member in your class. This is helps prevent others to change your static member to non-static one (cause compiler will complain)

2. Use final on method parameter and even local variable. You don't want other people who change your code against your original design

3.  When you add test cases, remember to add complex/edge cases. Don't make your test pass easily.

4. Defensive programming on null pointer exceptions. I've found this link

5. The best way to create a singleton [link]

6. Final your utility class and disallow instantiate by private default constructor. ( Kotlin do this by default)

沒有留言:

張貼留言