2.1.2 Thinking Ahead Flashcards
What is the purpose of thinking ahead?
To make programs easy and intuitive for users to use.
Define inputs
Data which is entered into the system by the user.
Define outputs
The results that are passed back once the inputs have been processed.
What considerations do programmers need to make regarding inputs and outputs when thinking ahead?
- Method of input/output
- Data structures used
- Data types used
- Order of data
What are preconditions?
Requirements which must be met before a program can be executed.
Where can preconditions be defined?
Within the code or within documentation.
Examples of where preconditions are required
Stack functions
- Check that a stack is not empty when popping an element
Factorial functions
- The number passed in cannot be negative.
Advantages of including preconditions within the documentation accompanying a subroutine
- Reduces length of program
- Reduces complexity of program
- Saves time needed to debug and maintain a longer program
- Makes subroutines more reusable.
Define caching
The process of storing instructions or values in cache memory after they have been used, as they may be used again.
Benefit of caching
Saves time which would have been needed to retrieve and store the instructions from secondary storage again
How is caching used in storing web pages?
Frequently accessed web pages are cached, so the next time one of these pages is accessed, content can be loaded without any delay.
Advantages of caching web pages
- Content loaded without delay
- Frees bandwidth for other tasks on a network
- Images and text do not have to be downloaded again multiple times
What is prefetching?
Algorithms predict which instructions are likely to soon be fetched. They are loaded and stored in cache before they can be fetched.
Caching limitations
- How accurate the caching algorithms are
- How effective the algorithms are in managing cache
- Size of cache
Give three advantages of using reusable program components
- More reliable than new components, as they have already been tested.
- Time and money is saved, as you do not need to develop from scratch.
- Can be used in future projects