CodeGaffes
Coding Practices - both good and bad.
Look to understand the reasons why these are recommended or bad. In a sense, these are like design patterns, only in miniature. By and large, they apply to all three languages, C#, Java, and C++.
A Null Reference Exception bug is reported. You check the code and find the problem happened because a public field wasn't set. You avoid the bug by modifying the code to check for a null. And you make it home in time for dinner. Original Code: myClass.MyField.MyMethod(); // Gets NullReferenceException on MyField “Corrected” Code: // Avoids NPEif ( myClass.MyField != null ) { myClass.MyField.MyMethod();} Seems like a reasonable solution. But guess what–this is nearly always the...