2.1.2 Thinking Ahead Flashcards
1
Q
Inputs and Outputs
A
- Designing a solution requires thinking ahead about how the different components of a problem can be handled in the best possible way.
- By thinking ahead, developers can build programs that are easy and intuitive to use.
- All computational problems consist of inputs which are processed to produce an output.
- Inputs include any data required to solve the problem, entered into the system by the user.
- Outputs are the results that are passed back once inputs have been processed; they are essentially the solution to the problem.
- You should be able to evaluate the methods using which this data is captured or relayed back to the user once processed, considering data structures and data types involved, as well as input and output devices.
- Designers begin by considering the outputs based on the user’s requirements, which is used to identify the inputs required and how these need to be processed to achieve these outputs.
2
Q
Preconditions
A
- Requirements which must be met before a program can be executed.
- Can be tested for within the code or included in the documentation accompanying a particular subroutine, library or program.
- Specifying preconditions means that a subroutine expects the arguments passed to it to meet certain criteria.
- Including preconditions within documentation reduces the length and complexity of the program and saves time spent on debugging and maintenance.
- Preconditions make subroutines more reusable.
3
Q
Reusable Components
A
Commonly used functions can be packaged into libraries for reuse.
Teams might create a library of components so they can be reused throughout an project.
Reusable components include:
- Abstract data structures eg. queues and stacks
- Classes
- Subroutines eg. functions and procedures
Problem decomposition is used to identify where previously-developed program components can be reused.
Reusable components are more reliable than newly-coded components, as they have already been tested.
They save time, money and resources.
Components may need to be modified to be compatible with existing software.
This can be more costly and time-consuming than developing them from scratch.
4
Q
Benefits of Using Reusable Components
A
- One piece of code can be used many times / in multiple places / makes code more efficient
- No need to write the same code multiple times
- Takes less time to plan/design/code the program
- Easier error detection as fix once and it corrects in each place // less likely to have errors as code is not written multiple times
- Makes it easier to maintain the program
5
Q
Caching
A
- Storing instructions or values in cache memory after they have been used, as they may be used again.
- Saves time of retrieving instructions from secondary storage again.
- Frequently-accessed web pages are cached so content can be quickly loaded
- This frees up bandwidth for other tasks on a network.
- Prefetching is when algorithms predict which instructions are likely to soon be fetched and are loaded and stored in cache.
- Thinking ahead means less time is spent waiting for instructions to be fetched.
- Limited by accuracy of algorithms used, as data stored in cache is not always used.
- Effectiveness depends on caching algorithm’s ability to manage the cache:
- Larger caches take a long time to search, but smaller cache sizes limit how much data can be stored.
- Can be difficult to implement well.