This note aims at introducing the fundamental elements of a computer program, including Python programs, as well as the common types of errors that could occur in computer programming.

Programming glossary

The following table contains some technical programming phrases that are often used and heard in the field of computer science and programming, that you need to be familiar as well.

Table 1. Some programming phrases that are discussed in this note. The boldface words in the description column indicate items that are expressions with their own description in this table.
Expression Description
algorithmA general method for solving a class of problems.
bugAn error in program that has to be resolved for successful execution of the program.
compiled languageA programming language whose programs need to be compiled by a compiler in order to run.
compilerA software that translates an entire high-level program into a lower-level language to make it executable.
debuggingThe process of finding and removing any type of error in the program.
exceptionAn alternative name for runtime error in the program.
executableAn object code, ready to be executed. Generally has the file extension .exe or .out or no extension at all.
formal languageA language that is intentionally designed for specific purposes, which, unlike natural languages, follows a strict standard.
high-level languageA programming language (e.g., Python, Fortran, Java, etc) that has high level of abstraction from the underlying hardware.
interpreted languageA programming language whose statements are interpreted line-by-line by an interpreter and immediately executed.
low-level languageA programming language that has a low-level of abstraction from computer hardware and architecture, such as Assembly. Very close to machine code.
natural languageA language that evolves naturally, and has looser syntax rules and standard compared to formal languages.
object codeThe output of a compiler after translating a program.
parsingReading and examining a file/program and analyzing the syntactic structure of the file/program.
portabilityA program's ability to be exucatable on more than one kind of computer architecture, without changing the code.
problem solvingThe process of formulating a problem and finding and expressing a solution to it.
programA set of instructions in a that together specify an algorithm a computation.
runtime errorAn error that does not arise and cause the program to stop, until the program has started to execute.
scriptA program in an interpreted language stored in a file.
semantic errorA type of error in a program that makes the program do something other than what was intended. Catching these errors can be very tricky.
semanticsThe meaning of a program.
source codeA program in a high-level compiled language, before being compiled by the compiler.
syntax errorA type of error in program that violates the standard syntax of the programming language, and hence, the program cannot be interpreted or compiled until the syntax error is resolved.
syntaxThe structure of a program.
tokenOne of the basic elements of the syntactic structure of a program, in analogy with word in a natural language.
dictionaryA collection of `key:value` mapping pairs, in which the values can be obtained by calling the value's key.
hashableA Python object (e.g., variable) that has a hash value which never changes during its lifetime.
immutableA variable or value that cannot be modified. Assignments to elements of immutable values cause a runtime error. Example immutable Python entities are tuples and strings.
invocationThe process of calling an object's method, usually done through <object name>.<method name> notation.
listA sequence of comma-separated heterogenous values next to each other.
methodSimilar to a function, a method is a predefined built-in Python script that performs a specific task on the data object to which the method belongs.
mutableA variable or value that can be modified. Examples of mutables in Python are lists, and dictionaries.
setAn unordered collection of unique elements, just like the mathemtical sets.
stringA sequence of characters next to each other.
tupleAn immutable data value that contains related elements. Tuples are used to group together related data, such as a person’s name, their age, and their gender.

The contents of a computer program

Although different programming languages look different in their syntax standards, virtually all programming languages are comprised of the following major compnents (instructions):

  1. input
    Virtually every program starts with some input data by the user, or the input data that is hard-coded in the program.

  2. mathematical/logical operations
    Virtually all programs involve some sort of mathematical or logical operations on the input data to the program.

  3. conditional execution
    In order to perform the above operations on data, most often (but not always) there is a need to check if some conditions are met in the program, and then perform specific programming instructions corresponding to each of the conditions.

  4. repetition / looping
    Frequently it is needed to perform a specific set of operations repeatedly in the program to achieve the program’s goal.

  5. output
    At the end of the program, it is always needed to output the program result, either to a computer screen or to a file.

Debugging a program

As it is obvious from its name, a bug in a computer program is annoying programming error that needs fixing in order for the program to become executable or to give out the correct answer. The process of removing program bugs is called debugging. There are basically three types of programming bugs (errors):

Syntax error


A program, whether interpreted or compiled, can be successfully run only if it is syntactically correct. Syntax errors are related to the structure and standard of the language, and the order by which the language tokens are allowed to appear in the code. For example, the following Python print statement is a syntax error in Python 3 standard, whereas it was considered to be the correct syntax for print in Python 2 standard.

print 'Hello World!'
  File "<ipython-input-21-10fdc521e430>", line 1
    print 'Hello World!'
                       ^
SyntaxError: Missing parentheses in call to 'print'

The syntactically-correct usage of print in Python 3 would be,

print ('Hello World!')  
Hello World!

Runtime error

Runtime errors or sometimes also named exceptions are a class of programming errors that can be detected only at the time of running the code, that is, they are not syntax errors. Examples include:

  • memory leaks (very common error in beginner C and C++ codes)
  • uninitialized memory
  • access request to an illegal memory address of the computer
  • security attack vulnerabilities
  • buffer overflow

These errors can be sometimes tricky to identify.

Semantic error

Unlike syntax errors that comprise of something the compiler/interpreter does not understand, semantic errors do not cause any compiler/interpreter error messages. However, the resulting compiled/interpreted code will NOT do what it is intended to do. Semantic errors are the most dangerous types of programming errors, as they do not raise any error flag by the compiler/interpreter, yet the program will not do what it is intended to do, although the code may look perfectly fine on its face. A semantic error is almost synonymous with logical error. Dividing two integers using the regular division operator / in Python 2 and expecting the result to be real, would result in a semantic error. This is because, in Python 2 standard, the regular division operator is equivalent to integer division for integer operands:

In Python 2,

2/7
0

Whereas, you might have really meant a float division by using /, as in Python 3,

2/7
0.2857142857142857