Anti-pattern: redundant else branch containing the protection condition / error handling

Often you see this code:

public void bla() { if (conditionTrue) { // long code here } else { // otherwise do nothing return; } // some more code } 

The else branch, obviously, is some kind of protective sentence that has shifted down, the indentation for the long code section can be smoothed out:

 public void bla() { if (!conditionTrue) return; // long code here // some more code } 

Some experts will cope with this by putting these extra branches in 3, 4 or 5 levels, creating code that is absolutely difficult to read.

I know these places somehow touching this topic:

Is this a named anti-pattern and what is its name?

+6
source share
1 answer

It smells like an anti-pattern arrow code

+7
source

Source: https://habr.com/ru/post/902491/


All Articles