2.2.1 Programming techniques

Cards (6)

  • Passing a parameter by value means that the parameter variable receives a copy of the data it was given. Passing by reference means it gets a reference to the data, meaning it can actually change the value of a variable passed into a function
  • IDE is short for Integrated Development Environment - software for editing, running and debugging programs
  • The basic programming constructs are sequence (doing one thing after another), iteration (loops) and branching (making decisions, e.g. if statements).
  • Global variables are scoped to the entire program, meaning they can be accessed anywhere in the program. Local variables have the scope of the function they're declared in (or sometimes less). Local variables are preferable, as global variables can lead to messy and buggy code.
  • Recursion is where a function calls itself. A recursive function must also have a base case, which is where the recursive calls stop. e.g. the factorial function (written as n!) is where you mulitply a number by a sequence of other numbers down to zero, such as 5! = 5 x 4 x 3 x 2 x 1. The recursive approach to this function would be to define 5! as 5 x 4!, then 4! as 4 x 3!, etc, until the base case where 1! = 1.
  • Functions and procedures are blocks of code which are used to perform a specific task. Each function or procedure has a name, and can have zero or more parameters, which are variables that store the inputs (arguments) to the function/procedure. A procedure doesn't return a value, whereas a function does.