Thinking Ahead Flashcards
What is a precondition?
A condition that must always be true (or false) for our given problem.
Example:
It’s 5pm and Tony has no money. He
forgot his phone & wallet at home! He needs to get home in time for dinner which is at 6pm.
He can either take:
- a taxi (which would take 10 mins)
- a bus (which would take 30 mins)
- or walk (which would take 55 mins)
What is your solution?
Preconditions:
- Tony cannot use any money.
- Tony must be home by 6pm.
- These directly affect our solution.
- Tony must walk.
Be specific!
Preconditions must evaluate to either TRUE or FALSE.
Don’t say Tony can’t be late, say Tony must be home before 6pm.
Don’t say money, say Tony cannot use any money.
What is the nature of caching?
Caching is a technique used to store frequently accessed data temporarily so it can be retrieved quickly when needed.
What are the benefits of caching?
Improved performance,
- Caching reduces the time required to access frequently used data, leading to faster processing.
Cost efficiency,
- Caching can reduce bandwidth usage and decrease reliance on expensive resources.
What are the drawbacks of caching?
Stale data,
- Cached data may become outdated if the original data changes and the cache isn’t updated immediately, leading to incorrect results.
Added complexity,
- Implementing cache increases complexity, requiring developers to carefully design and maintain the cache to avoid issues.
What’s the need for reusable program components?
- Saves us time as we don’t have to recreate these.
- We can import them and use them in many places. So when we want to make changes to the reusable component we only need to make that change once.
- Our code will be shorter because we are avoiding duplication.
- The reusable components would have been tested and would be reliable which would increase our code’s reliability.