2.1.2 Thinking Ahead Flashcards

1
Q

Thinking Ahead

A

Thinking Ahead : Identify desired output and work back to find inputs needed to solve the problem and helps identify preconditions.

  • Important to consider preconditions : Requirements that must be met before program can be executed (e.g. Check stack is not full before adding item)
  • Preconditions ensure necessary checks are carried out before execution of subroutine so no errors occur.
  • Also Includes identifying data that can be Cached so faster access speeds to frequently used data and instructions.
    -Also includes identifying reusable components that can be called multiple times or packaged into libraries so less code needs to be written.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Thinking Ahead - Preconditions

A

Preconditions : Requirements that must be met before program can be executed (e.g. Check stack is not full before adding item or list must be sorted for Binary search or non - empty values/lists)
- Preconditions ensure necessary checks are carried out before execution of subroutine.

Advantages :
- Can make program components reusable - clearly documenting preconditions helps make functions reusable - explicitly ensure preconditions are met.

  • Cutting out unnecessary checks - clear statement of preconditions helps programmer know what checks are needed before calling sub-procedure and which checks are unnecessary.
  • Helps make program easier to debug and maintain - clearer shorter programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Thinking Ahead - Caching

A

Caching : The process of storing frequently used data in cache memory after they have been used in case it is needed again, allowing for faster access for future use.
- Can be web caching which stores HTML pages and images or CPU caching

Advantages :
- Faster access for previously searched items
- Saves on costly bandwidth
- Reduced load on web services

Disadvantages :
- Relies on same data being needed multiple times
- increased complexity of programs to make use of caching

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Thinking Ahead - Reusable Components

A
  • Can decompose problem into smaller simpler tasks and think ahead about how each task can be solved and reuse program components developed in past / externally and package into libraries for future use.
  • Can program as self contained subroutines or classes - both can be reusable.

Advantages :
- Commonly used functions packaged into libraries - can be reused across multiple programs and projects which saves time.
- Reusable components may have already been tested - saves time as do not need to be debugged again.
- Saves times as code does not need to be rewritten
- More efficient code which will use less memory//be easier to maintain
- May require less technical knowledge as code can used rather than written.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Problem Decomposition Advantages

A

Procedures can be re-used in same program or packaged into libraries
- No need to reprogram/saves time

Program can be split between programmers
- Can specialize in their area

Speed up completion time
- As multiple procedures worked on concurrently

Easy to test/debug
- As each module can be tested on its own then combined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly