I was just reading the top 100 signs of spaghetti code and I came across number 4, which simply states:
if ($status == "awake"){
$actitivity = "Writing spaghetti code";
} else if ($healthstatus == "OK"){
$activity = "Sleep";
} else {
print "CALL 911 IMMEDIATELY!";
}
I've seen this multiple if-else pattern in other spaghetti discussions. I'm a little confused why this is, and even if it's applicable to this example.
Is the above example bad because
the first variable is
actitivity
which indicates the coder needs some sleep, so it's a joke, orview shouldn't be being output during logic, or
something about too many if/else
EDIT never mind this second part, it's bad because of nested conditionals and multiple returns
In the other spaghetti discussions link, is it bad because
- the logic has return
in it, which breaks the flow, or
- there's too many if/else
piled on top of eachother...?