Once doing Code Review I found a code snippet like this and so thought would share my experience here.
CDialog *SomeDialog = new CMyDialog(<<Some Param>>); SomeDialog->SomeFunction(this);
In the above code we always assume that SomeDialog is always allocated with the CMyDialog class pointer but that may not be the case always and so its always better to have the code as follows.
CDialog *SomeDialog = new CMyDialog(<<Some Param>>); if(SomeDialog != NULL) { SomeDialog->SomeFunction(this); }
and it would always make your programming effort safer and subject to less crashes.








{ 5 comments… read them below or add one }
Thank you for your help!
Hi! I`m totally disagree with you point.
Hi! I`m totally disagree with you point.
this is also known as defensive programming…
I do not agree on this because its safe and not defensive. I am making it safe from case but defensive may not be the right word.