Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

DIT 0202: INTRODUCTION TO

PROGRAMMING AND
ALGORITHMS
WEEK 4: INTRODUCTION TO PROGRAMMING CONCEPTS
Diploma in Information Technology
Stage II
Lecturer: Mr. Alvin Mdachi
By the end of this lecture the student should
be able to:
• Describe the difference between HLL and LLL
• Define a program and programming language.
• Know the different types of errors that occur in a program
• Explain the difference between formal and natural languages
• Understand the difference between an interpreter and a compiler
High Level Machine Languages
• A high-level language is any programming language that enables
development of a program in a much more user-friendly programming
context and is generally independent of the computer's hardware
architecture.
• designed to be used by the human operator or the programmer.
• their programming style and context is easier to learn and implement than
low-level languages, and the entire code generally focuses on the specific
program to be created.
• every single program written in a high-level language must be interpreted
into machine language before being executed by the computer.
• BASIC, C/C++ and Java are popular examples of high-level languages
Low-Level Language
• Aka Machine language or Assembly language or Computer’s native
language.
• A low-level language is a programming language that deals with a
computer's hardware components and constraints.
• designed to operate and handle the entire hardware and instructions set
architecture of a computer directly.
• Considered to be closer to the computer
• Programs and applications written in a low-level language are directly
executable on the computing hardware without any interpretation or
translation.
• Machine language and assembly language are popular examples of low-
level languages.
• computers can only execute programs written in low-level
languages. Thus, programs written in a high-level language have to
be translated before they can run. This translation takes some time,
which is a small disadvantage of high-level languages.
• The advantages of using high level languages:
1.it is much easier to program
2.High-level languages are portable
What is an interpreter ?
• An interpreter is a program that reads a high-level program and
does what it says.
• It then translates the program line-by-line, alternately reading lines
and carrying out commands.
What is a compiler?
• A compiler is a program that reads a high-level program and
translates it all at once, before executing any of the commands.
• The high-level program is called the source code, and the translated
program is called the object code or the executable.
What is a program?
• A program is a sequence of instructions that specifies how to
perform a computation.
• Programming is the mental process of thinking up instructions to
give to a machine (like a computer).
• Coding is the process of transforming those ideas into a written
language that a computer can understand.
• A programmer is an individual that writes/creates computer
software or applications by giving the computer specific
programming instructions.
Basic Operations in Programming
• Input: Get data from the keyboard, or a file, or some other device.
• Output: Display data on the screen or send data to a file or other
device.
• Math: Perform basic mathematical operations like addition and
multiplication.
• Testing: Check for certain conditions and execute the appropriate
sequence of statements.
• Repetition: Perform some action repeatedly, usually with some
variation.
What is debugging?
• Debugging is the process of tracking down and correcting
programming errors (bugs)
• There are 3 main types of errors:
1. Compile-time errors/Syntax errors
2. Run-time errors
3. Logic errors and semantics
Compile-time errors
• Also known as Syntax errors
• Syntax refers to the structure of your program and the rules about that
structure.
• These errors are mainly occurred due to the mistakes while typing or do
not follow the syntax of the specified programming language.
• If there is a single syntax error anywhere in your program, the compiler
will print an error message and quit, and you will not be able to run
your program.
• Commonly occurred syntax errors are:
➢If we miss the parenthesis (}) while writing the code.
➢Displaying the value of a variable without its declaration.
➢If we miss the semicolon (;) at the end of the statement.
Run-time errors
• A runtime error in a program is an error that occurs while the
program is running after being successfully compiled.
• Most run-time errors C occur because the language provides no
protection against the accessing or overwriting of data in memory.
• The main cause or run time errors is because the program is not
able to perform the operation during the process of running it.
Logic errors and semantics
• The logical error is an error that leads to an undesired/incorrect
output.
• If there is a logical error in your program, it will compile and run
successfully, in the sense that the computer will not generate any
error messages, but it will not do the right thing.
• The meaning of the program (its semantics) is wrong.
• These types of mistakes are mainly done by beginners.
• Identifying logical errors can be tricky, since it requires you to work
backwards by looking at the output of the program and trying to
figure out what it is doing.
Formal and natural languages
• Natural languages are the languages that people speak, like English, Spanish, and
French.
• Formal languages are languages that are designed by people for specific
applications.
• Programming languages are formal languages that have been designed to express
computations.
• Formal languages have strict rules about syntax
• Syntax rules come in two flavors, pertaining to tokens and structure:
• Tokens are the basic elements of the language, like words and numbers and
chemical elements.
• The second type of syntax rule pertains to the structure of a statement; that is, the
way the tokens are arranged.
• When you read a sentence in English or a statement in a formal language, you have
to figure out what the structure of the sentence is (although in a natural language
you do this unconsciously). This process is called parsing.
Assignment 1 Due on FRIDAY 28/01/2022
Computer scientists have the annoying habit of using common
English words to mean something different from their common
English meaning. For example, in English, a statement and a
comment are pretty much the same thing, but when we are talking
about a program, they are very different.

a. In computer jargon, what’s the difference between a statement


and a comment?
b. What does it mean to say that a program is portable?
c. What is an executable?

You might also like