if statement is often used in almost every code. Unfortunately it reduces readability of source code and may influences of performance (but rather in low level programming languages). Below I show examples of
if and propositions of improvements.
Often there’s need to change variable or return value depending on some condition. Instead of if/else it’s better to use conditional operator:
When you create new, big object, check whether lazy initialization really improve performance. If not, early initialization is simpler.
Empty collection instead of null
When a method return a collection you must chcek if it’s not null before iterate unless you are sure it return empty collection instead.