forked from Dev-Outreach/bad-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Deep Nesting
TStream edited this page Apr 21, 2017
·
2 revisions
- too many levels of nesting are make code hard to read.
- most of the time can rearrange code to reduce nesting.
Deep Nesting Example 1:
public boolean do_stuff() {
if (this_thing) {
if (and_this) {
if (also_this) {
if (aswell_this) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}Deep Nesting Example 2:
public int do_stuff() {
if (this_thing) {
if (and_this) {
if (also_this) {
if (aswell_this) {
return 1;
} else {
return 2;
}
} else {
return 3;
}
} else {
return 4;
}
} else {
return 5;
}
}