Tuesday, September 23, 2008

small annoying bugs :-(

Sometimes when you debugging a code, You don't expect a bug in project settings and you may spend hours to find it.

Here is some suggestions that may help you with it.
This is applicable to mobile development:

1. All resources line memory allocation, files, etc., you need to put in a wrapper: shared_ptr myPointer(rawPointer)

2. All unexpected behavior line "low memory" should throw an exception and exit.

class MyDataBlock
   char* mData;
   MyDataBlock():mData(int size)
      ASSERT(size>0,"wrong size");
      mData = new char[size];
      ASSERT(mData,"low memory");

      delete[] mData;

3. Logs
  • developer logs - you must have them if there is no way to run application in debug mode. This is more applicable to OS driver development or other specific domain development.
  • when exception happen try to log stack. When application crashes it is very useful to have function calls stack. 

No comments: