You should test for these values every time you call the API function. The above example of OpenDataFile is a primitive way of wrapping fopen with error-checking code which throws an exception if fopen fails. Make your code const-correct Use const wherever possible. Before you write a block of code, write the comment for it. If you can't write a clear comment first, you can't write clear code.
Some people tend to restate the code in their comments.
Your comments should be for usage and intent. That is, when you declare a variable, put a comment next to it saying what it's used for. When you have a block of code that does something, comment the entire block of code describing what it does. Many educational style guides suggest that students put large comment blocks above each function. This is ridiculous.