Basic Programming Concepts

Ideal Program Framework

Functions - a single output value results from a list of input variables.

      output_value = function(input variables: var1,var2....)
Subroutines - The exact definition of a subroutine will change from one language to the next. in MatLab, a list of input variables results in a list of output variables. In all other languages that we know of, a single variable list is used for both input and output. From the computer's point of view ALL these variables are input, ALL are modified during the course of the subroutine (they have one value going into the subroutine and are possibly given a different value somewhere in the subroutine), and then ALL these modified variables are output. From the programmer's point of view, some variables are input (and are never redefined in the subroutine), some variables are modified, and some variables are input with "dummy" values so that they can be given output values during the course of the subroutine. Which of these three categories the variables fall under depends on how the subroutine is written.
computer view:    subroutine(variables to be modified: var1,var2,var3,var4,var5)
Programmer view:  subroutine(INPUT ONLY: var1,var2; OUTPUT ONLY: var4,var5; MODIFIED: var3)

Below is a schematic diagram of a program. A more detailed example can be found here.

************ MAIN PROGRAM **********************

program description

variable definitions

call subroutine1(variables in, variables out, variables to be modified)
variable_out = function1(variables in)
call subroutine2(variables in, variables out, variables to be modified)
etc, etc

******** subroutine1 ******************************

variable list: in, out, modified

description of subroutine

extra variable definitions (if needed)

command1
command2
etc. etc.

******** function1 ******************************

list of input variables

description of function

variable definitions (if needed)

command1
command2
etc. etc.

return variable_out

********************* etc. etc. ************************

Programming Terminology

These are in something like logical order