Thinking Ahead Flashcards
What is the Advantage of Thinking Ahead
- Allows developers to consider problems that may arise later
- Taking these factors into account at an early stage, developers can design strategies to make programs easy and intuitive to use
What are the Elements of Thinking Ahead
- Inputs and Ouputs
- Preconditions
- Cashing
- Decompoistion
Describe the Inputs and Ouputs of Thinking Ahead
- Inputs include any data that is required to solve a problem and the method of input
- Outputs are the results that are passed back once the inputs have been processed and the problem solved
- Designers must decide on a suitable data type, structure and method to use in order to present the solution
Why is good to specificy preconditions
Specifying preconditions means that a subroutine can expect the parameters to meet certain criteria
What are Preconditions
Requirements which must be met before a program can be executed
Why is it good to specificy preconditions in the documentation accompying code
- Reduces the length and complexity of the program
- Saves time needed to debug and maintain a longer program
- Sub-rountines can be reused without error
Describe examples of some methods and their preconditions
- Linear search - data must be in a structure that can be moved through one element at a time
- Binary search - data must be in order and must be in a structure where elements can be directly accessed
- Binary search tree - data must be stored in a tree structure and ordered to allow a binary search
- Hash table - data must be stored in a hash table and the method of dealing with collisions must be understood
How is Cashing used in Thinking Ahead
- Caching is the process of storing data in cache memory after it have been used
- This saves time which would have been needed to store and retrieve the data again
- When you are designing your own programs, you should pay attention to any areas where caching might be beneficial
- If you need to process all of the records in a file, it might be more effective to read the whole file into an array, and carry out subsequent processes against the array, than to repeatedly read and write to an external file
What are the Potential Drawbacks of Caching
- Cache can become outdated if original is updated leading to inconsistences in the data (secuirty risk against data protection if stayed in cahce for a long time)
- Larger cache takes long time to search through
- Takes up storage space
- Only limited storage space
What is Prefetching
- A more advanced variation of caching
- In which algorithms predict which instructions are likely to soon be fetched
- The instructions and data are loaded and stored in cache before they are fetched
- By thinking ahead, therefore, less time is spent waiting for instructions to be loaded into RAM from the hard disk
What are the Limitations of Prefetching
- The accuracy of the algorithms used in prefetching is a limitation, as they can only provide an informed prediction as to the instructions which are likely to be used and there is no guarantee that this will be right
- The effectiveness of caching depends on how well a caching algorithm is able to manage the cache, larger caches still take a long time to search and so cache size limits how much data can be stored
How is Decomposition used in Thinking Ahead
- By breaking the task into smaller simplier tasks
- It allows programers to identify where program components developed in the past, or externally-sourced program components, can be reused to simplify the development process
- Common reused used functions are libraries
What are the Advantages of using Reusable Components
- Better tested so more reliable
- Saves time creating code
- Saves development costs.
- However, it may not always be possible since components may not be compatible