For example I can do:
public void onSomethingClick() {
if (text.isEmpty()) {
showMessage("The text is empty, put some text in the input");
} else {
//Do the things that you do if the text isn't empty here...
}
}
Or I can do this:
public void onSomethingClick() {
if (text.isEmpty()) {
showMessage("The text is empty, put some text in the input");
return;
}
//Do the things that you do if the text isn't empty here...
}
Sometimes it is more legible do it the first way, instead of keeping nesting if
/else
statements. Is there some convention about this? Any pitfalls to watch out for?