Pattern: Unnecessary statement
Issue: -
Statements which have no clear effect are usually unnecessary, or should be broken up.
Example of incorrect code:
myvar;
list.clear;
1 + 2;
methodOne() + methodTwo();
foo ? bar : baz;
Though the added methods have a clear effect, the addition itself does not
unless there is some magical overload of the +
operator.
Usually code like this indicates an incomplete thought, and is a bug.
Example of correct code:
some.method();
new SomeClass();
methodOne();
methodTwo();
foo ? bar() : baz();
return myvar;