What?
Simplest control flow: placing statements and statement blocks in sequence
Why?
Although organizing code with a straight line is a simple task, some of the nuances in the code structure still affect the code quality, correctness, readability, and maintainability.
How? Must have statements in a clear order
- Make the dependency very obvious
- Enable subroutine names to highlight Dependencies
- Use subroutine parameters to indicate dependency
- Notes
- Check dependencies with asserted/error handling code
Order-independent statements
- Make the code easy to read from top to bottom and organize the relevant code together
// badMarketingData marketingData;SalesData salesData;TravelData travelData;travelData.computeQuarterly();salesData.computeQuarterly();marketingData.computeQuarterly();salesData.computeAnnual();marketingData.computeAnnual();travelData.computeAnnual();marketingData.print();slaesData.print();travelData.print();// goodMarketingData marketingData;marketingData.computeQuarterly();marketingData.computeAnnual();marketingData.print();SalesData salesData;salesData.computeQuarterly();salesData.computeAnnual();slaesData.print();TravelData travelData;travelData.computeQuarterly();travelData.computeAnnual();travelData.print();
Code complete ch.14 organizes code for a straight line