You have a sequence of functions to execute. Case A: They do not depend on each other. Which of these is better?
function main() {
a();
b();
c();
}
or
function main() {
a();
}
function a() {
...
b();
}
function b() {
...
c();
}
Case B: They do depend on successful completion of the previous.
function main() {
if (a())
if (b())
c();
}
or
function main() {
if (!a()) return false;
if (!b()) return false;
c();
}
or
function main() {
a();
}
function a() {
... // maybe return false
b();
}
function b() {
... // maybe return false
c();
}
Better, of course, means more maintainable and easier to follow.
Case A: 1.
Reasoning: Since none of the functions depend on each other, calling them in order in main shows a logical sequence of events. Your alternative where they call the next one at the end of each function just looks like spaghetti code, and is hard for someone reading your program to follow.
Case B: None of the above.
function main() {
return a() && b() && c();
}
Reasoning: It seems you don't really care about the return value, you just want to break out early if one of the functions returns a certain value. You can return the "anded" result of all of these functions, and if any one of these returns false the code will break out early. So, if a returns false then b wont be executed. Placing all of them on one line is easy to read and concisely shows that they are dependent on each other.