8.1: Programming Principles
Eduqas / WJEC
There are four stages to computational thinking (smart problem solving).
Decomposition is when you break a problem down into smaller tasks so that it is easier to solve.
Pattern Recognition is the process of identifying similar patterns within a problem.
Abstraction is when you ignore unnecessary information and focus only on the important facts.
Algorithms are the final stage as step-by-step rules are created to solve the problem. An algorithm is usually written as psuedocode or presented as a flowchart.
There are three constructs (ideas) of programming that most programs will contain:
Structuring code into a logical, sequential order.
Decision making using if statements.
Repeating code, often using for loops or while loops.
Large programs are often modular - split into subroutines with each subroutine having a dedicated purpose.
Local variables are declared within a specific subroutine and can only be used within that subroutine.
Global variables can be used at any point within the whole program.
Local variable advantages
Saves memory - only uses memory when that local variable is needed - global variables use memory whether they are used or not.
Easier to debug local variables as they can only be changed within one subroutine.
You can reuse subroutines with local variables in other programs.
Global variable advantages
Variables can be used anywhere in the whole program (and in multiple subroutines).
Makes maintenance easier as they are only declared once.
Can be used for constants - values that remain the same.
Local & Global Variables
A variable is data that can change in value as a program is being run.
A constant is data that does not change in value as the program is run - it is fixed and remains the same.
An example of a constant in maths programs is pi - it will constantly remain at 3.14159 and never change.
Counts & Rogue Values
When using iteration (looping) the loop must eventually be able to stop. A count is a variable that is used to record the current iteration (loop number).
A rogue value is an unexpected value that will cause the loop to end. For example by typing "Stop" into a loop that asks for numbers.
An efficient program will use variables with sensible names that immediately state their purpose in the program.
Using variable names like 'TotalNum' and 'Profit' rather than 'num1' and 'num2' mean that other programmers will be able to work out the purpose of the code without the need for extensive comments.
8.1 - Programming Principles:
1. What is meant by 'decomposition'? Why is it important? 
2. What does the term 'abstraction' mean? Why is it important? 
3. What is pattern recognition? 
4a. What is an algorithm? 
4b. What are the two ways of writing an algorithm? 
1. Describe and draw a diagram for the 3 programming constructs. 
1. What is the difference between local and global variables? 
2. Describe two advantages of using local variables. 
3. Describe two advantages of using global variables. 
4. What is a constant? Give an example. 
5. Why is it important to use self-documenting identifiers when programming? 
6. What is a count? What is a rogue value?