The Stepdown rule encourages to read the code like a top-down narrative. It suggests every class/function to be followed by those at the next level of abstraction so we can read the code descending in the level of abstraction.
In C/C++ you need to declare classes/functions before you use them. So how would cleanly apply the Stepdown rule here? What are some pros and cons of the following approach? Any better one?
void makeBreakfast();
void addEggs();
void cook();
void serve();
int main()
{
makeBreakfast();
}
void makeBreakfast()
{
addEggs();
cook();
serve();
}
void addEggs()
{
// Add eggs.
}
void cook()
{
// Cook.
}
void serve()
{
// Serve.
}
My approach is like yours but with either making a class so the declaration can come after use, or put declarations in a header file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With