C++/C# bad practices: learn how to make a good code by bad example

Rosegarden

V668 There is no sense in testing the ‘file’ pointer against null, as the memory was allocated using the ‘new’ operator. The exception will be generated in the case of memory allocation error. SF2PatchExtractor.cpp 94

There is an interesting code fragment for file handling. It seems that a developer inspired by such programming languages as C# and Java. Otherwise, it is not clear why not to create an instance of ifstream type just as a variable on the stack. Dynamic memory allocation is clearly redundant and, in addition, caused an error.

Here is a list of issues of this code fragment:

Code is excessively difficult;

A check of the pointer here makes no sense (new operator will throw an exception if it cannot allocate memory for an object);