ProgrammingSequence, selection, iteration, procedures, functions, modules, parameters, compilers, interpreters

Syllabus Detail

  • constants 11 ATAR, 12 ATAR
  • local, global, parameters 12 ATAR
  • naming conventions 11 ATAR, 12 GEN, 12 ATAR
  • used in programming and also in pseudocode 11ATAR

Background

  • Programming is all about writing the most efficient code to achieve a specific task
  • By using variables and constants, we're able to store values temporarily
  • These values can then be referenced or re-used to perform other tasks and functions
  • Variables and constants are used in both programming and pseudocode

 

Variables

  • A variable is a memory location that has its own associated name (known as an identifier)
  • Variables are simply temporary stores that a program can access to reference or re-use a value during execution
  • Unlike constants, variables can vary and have changing values
  • Variables are used religiously throughout programming as they streamline efficienecy and allow for easier referencing

 

Constants

  • A constant is another memory location that, like a variable, consists of an identifier and a value
  • Unlike a variable, however, a constant does not change in value
  • These are handy for fixed values such as the mathematical symbol Pi
  • Pi is a constant is the value does not change
  • Pi is given a symbol to represent the fixed value number, which is known as its identifier

 

Naming Conventions

  • A naming convention is simply a set of rules put in place to ensure organization and consistency of variables and constants
  • Many programming languages allow for a vast array of naming options for variables and constants
  • How variables and constants are named in a program are often up to the discression of the developer(s)
  • They're used to reduce the effort needed to read code as well as maintain consistency
  • Some variables and constants have system or programming language restraints, such as words reserved for predefined functions
  • It's generally sought after to name variables and constants with clear English words that relate to their use

Local Variables

  • local variable is a variable that is only accessible in the current code or module
  • To write code you need to set up numbers and words that can be read by the program
  • These numbers and words are given data types and values so they can be read.
  • For calculating the area of a rectangle we need to be able to use the following variables
    • length
    • width
    • total area
  • To make length, width and total area, variables we need a data type and a value (VB example)
    • Dim length As Double
    • Dim width As Double
    • Dim totalArea As Double

 

Global Variables

  • The purpose of a global variable is to provide a variable that is accessible from anywhere within the program. eg so other functions or modules can use them.
  • They are placed prior to other modules or functions.
  • So, a global variable can be used in a module, only if it is in the code prior to that code.
  • Ideally you want a variable to change, but as a global variable is used by different modules, it will cause confusion when it is changed.
  • Global variables are not used much as they are limited in what they can do.

Parameters

  • parameter is a referenced variable or constant that is passed to a function or module
  • We define a parameter of a function or module and tell the program what values are needed for it to operate
  • These parameters can be passed into and out of a function or module
  • They usually have brackets (parentheses) around them so are easy to find.

 

Further Research

  • Check out ProgramWiz's article on C Variables and Constants here
  • Check out Tuts+'s article on 9 Confusing Naming Conventions for Beginner's here
  • Check out CodingUnit's article on Global and Local variables here
  • Check out MSDN's article on Parameter Passing in C# here

 

Worksheet and Practice (yet to be added)

Found an error or have an enhancement? Please let us know via this contact form