Pointers vs references
C++ coders seem to overuse and abuse pointers. Frequently, they really should be using a reference instead of a pointer. It would definitely simplify maintaining code. For instance, I am going to create a method and have 2 options for the message signature:
void AClass::MyMethod(AItem * pItem)
or
void AClass::MyMethod(AItem & oItem)
In the first one, if I need to make changes to the code at a later date, what do I have to worry about? Well, what it pItem. Is it really, really an object or can it be NULL. Now in simple projects that's not an issue. You can hunt down all the places where MyMethod is used and decide how it is used.
However, in professional projects that have a million lines or so, that is not really an option AND it's not productive. It's not an option because there are just too many code pathways to conclusively determine the usage.
Some coders say, "Yeah, well I'll stick an ASSERT at the top of the method and everyone will know how it is to be used." The problem with that is in development it works fine and is fairly easy to catch issues. However, at runtime, that check goes away. If there is an error path that causes the pointer not to be set, execution falls into the method and real wackiness ensues.
I say if you meant for the method to have an object passed in, code it that way. By using the second method signature, it is unequivocal what the code meant. Plus, you don't get legacy methods where in parts of the method has:
if (pItem)
pItem->DoIt();
and then other parts of the method you get:
pItem->DoIt();
I wouldn't mind maintaining code, if the people who originally wrote it would write easy to maintain code.