A Journey 2 Eternity

List of BAD Coding Conventions

Posted on: November 26, 2007

1. Using unnecessary double pointers

GetNodeName(Node** ppNode)
{
	return *ppNode->GetName();
}

You should only use a double pointer when you are allocating your memory with new or malloc() inside a method and passing a pointer as argument to get the newly allocated memory address.

BOOL COM_CREATE_OBJECT(ComObj** pObj)
{
	ComObj* pNewObj = new ComObj;
	if(pNewObj) {
		*pObj = pNewObj;
		return TRUE;
	}
	return FALSE;
}

void main()
{
	ComObj** pObj = NULL;
	// in this case you have to use double pointer.
	COM_CREATE_OBJECT(&pObj);
}

2. Converting TCHAR to WCHAR (or WCHAR equivalent), or TCHAR to char (or char equivalent), by simple type casting.

WCHAR* nodeName = xmlPareser->GetNodeName();
TCHAR* convertedName = (TCHAR*) nodeName;

3. Assuming WCHAR, or wchar_t to be a typedef of unsigned short.

4. Using wierd macro function names such as Z(), W(), X(), etc.

WCHAR* fileNameW = GetFileNameW();
TCHAR* fileName = X(fileNameW); // here x is a function which converts wchar to tchar…

5. Returning temporary pointers as return type

TCHAR* convertUnicodeToTChar(WCHAR* str)
{
	TCHAR buf[255];
	wcstombs(buf, str);

	// returning temporary pointer … very dangerous indeed.., maybe u can
	// use a global or member variables in this case..
	return buf;
}

6. Doing Too Much Processing (such as running a big for loop) in OnMouseMove(), OnEraseBkGnd, OnPaint(), OnCmdUI() etc.

Advertisements
Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

November 2007
M T W T F S S
    Dec »
 1234
567891011
12131415161718
19202122232425
2627282930  

Blog Stats

  • 27,176 hits
%d bloggers like this: