Tuesday, July 30, 2013

Java Programmers Best Guidelines

1. Code should be READABLE. If not…please don’t code!
2. If you are using a DESIGN PATTERN, check with your lead, whether it is the right one in the given situation.
3. If you don’t COMMENT your code, you have not documented it.
4. If you did not make NULL CHECKS, your code will fail!.
5. If you use STATIC everywhere, you leave yourself open to memory issues.
6. If you do not handle EXCEPTIONS, you should not code, or review it.
7. If your code is not UNIT TEST able, you have not written it right.
8. Do not add Numbers directly as FLAGs or ENUMS, use readable constants instead.
9. EXTERNALIZE all User Visible Strings.  (Keeping it flexible for Multi-lang apps.)
10. Add Parameters that could change, in CONFIGURATION files.
11. Do not use Popup Message Boxes for Testing, use Console PRINT statements instead. You will forget to remove them!
12. Using LOGS in proper places, can enhance code, and avoid 11. in many cases. This is the only thing that will help you in remote communication from the customer end. Also helps in timing the functions and troubleshooting performance issues
13. Expose commonly used Utility Classes in UTILS package. Keep a note on its size, as not all Classes may need the whole package, it is a good practice.
14. Avoid practice of STAR importing (i.e importing whole Package e.g. java.lang.*)
15. When Synchronization is not needed, avoid using Synchronized Classes (e.g Do not use Vector when ArrayList would do the work).

(Thanks to friends who have contributed)

No comments: