If you are a sophisticated programmer, then you never use If-Else statements, else you’re a hack. At least that’s what I’ve been reading. Maybe those articles do have a point and maybe I would not have read them if their wording was not so extreme.

Inevitably, responses to those articles point out that anything worth doing on a computer involves making decisions. Indeed anything a computer does involves making decisions.

For example, let’s say that you go to a Local Global Bank ATM, put your ATM card in. If you are a Local Global Bank customer, you can proceed to PIN entry, else the ATM asks if you agree to a $5 service fee. If you agree, you proceed to PIN entry, else the ATM releases your card and you go on your merry way.

If you enter the correct PIN, you can proceed to transaction selection, else you’re given one or two more tries to enter the correct PIN. If you make too many incorrect attempts, the ATM “captures” your card.

By the way, that thing about using reverse PIN to alert the police to a thief is a complete myth; I’ve never heard a bank employee advise customers to not choose palindromes for their PINs. So that’s one less conditional branch for the ATM software to take into account.

Let’s say you’ve entered the correct PIN and selected to withdraw $80 from your savings account. If your savings account balance is $80 or more ($85 if the service fee applies), then the ATM dispenses $80, else the transaction is rejected for insufficient funds.

#software-development #cyclomatic-complexity #java #if-else

Deeply nested If-Else statements are the problem, not If-Else per se
1.15 GEEK