Note on Programming Practice

I have been attending 2 code review sessions since coming back from Tawau. Here's what I've learned.

  1. Put comment into the source code, i.e. what it does, and which function is calling it.
  2. Exception handling on HANDLE that could not be closed properly.
  3. Code that repeats several times can be put into 1 function. This way, it will be centralized and easy to debug.
  4. Pointer must be deleted to avoid memory leak.
  5. std:vector can be used instead of fix size array.
  6. It is better not to use query all statement to query everything out from the database.
  7. strncpy and strncat are safer way to manipulate string.
  8. Construct an exception class to throw error instead of throwing number.
  9. Don't use too much pointer if can.
  10. Database connection must be caught and handled.
  11. Have constant localized at 1 place. This way, it makes it more easy to manage.
  12. Declare only the functions that need to be interfaced with other class as public; otherwise the rest should be private.
  13. Use const keyword to avoid a variable being changed by a function.
  14. Hide the field, and use external method to access the field. This is to avoid the private field being exposed.
  15. Make the code portable.
  16. The unwanted/commented code should be deleted once it is confirmed.
  17. Use of std:auto_ptr to avoid memory leak.
  18. Have a fixed variable declared outside of the function loop instead of calling the function within the loop. It is a better practice to reduce the number of call time to the function that returns i.e. array size.
  19. 1 method/function should not exit 100 lines of code.
  20. There should only be at least 10 if...else... statement within a method.
  21. Try not to use new everywhere.
  22. Prevent too many nested if... else... statements if possible.
That's it. The list will be updated again.

Comments

Popular posts from this blog

Yahoo! Messenger voice call & video call disabled, why?

Sport's Injuries - Treatment for bruises

Web Development: Disable, Validate, & Enable Buttons