I'll try to be as brief as possible in respect to your time.
In a program divided up into many functions by which it is intended that they execute themselves one after another, when (if ever) is it preferred to:
A) Execute the functions one after another in main()?
or
B) Execute one function in main(), and have that function daisy chain to the rest of the functions that need to be executed?
To illustrate this
Program FlowChart:
Start -> Make foo -> Do bar? -> True -> Say Goodbye -> End
A:
void makeFoo() {
[...]
return;
}
bool doBar() {
bool bar;
[...]
return bar;
}
void sayGoodbye() {
[...]
return;
}
int main {
makeFoo();
if (doBar()) {
sayGoodbye();
}
return 0;
}
B: (Daisy Chain)
void makeFoo() {
[...]
doBar();
return;
}
void doBar() {
bool bar;
[...]
if (bar) {
sayGoodbye();
}
return;
}
void sayGoodbye() {
[...]
return;
}
int main {
makeFoo();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire