0% found this document useful (0 votes)
1 views21 pages

1.0 Introduction to Programming

This document provides an introduction to programming, defining key concepts such as programming languages, programming paradigms, and language translators. It differentiates between low-level and high-level languages, as well as procedural, object-oriented, and logic programming paradigms. Additionally, it explains the roles of assemblers, interpreters, and compilers as types of language translators.

Uploaded by

shidasia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views21 pages

1.0 Introduction to Programming

This document provides an introduction to programming, defining key concepts such as programming languages, programming paradigms, and language translators. It differentiates between low-level and high-level languages, as well as procedural, object-oriented, and logic programming paradigms. Additionally, it explains the roles of assemblers, interpreters, and compilers as types of language translators.

Uploaded by

shidasia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

1.

0 Introduction to Programming
Learning Outcome
At the end of this topic, students should be able to:

a) Define programming language, programming paradigm, and language


translators.
b) Differentiate Paradigm of Programming Language (Procedural, Object
Oriented & Logic)
c) Differentiate types of language translator (Compiler, Interpreter,
Assembler)

2
1.0 Definition – Programming Language
§ What is Programming Language?
• A programming language is a set of words,
abbreviations, and symbols that enables a software
developer / programmer to communicate
instructions to a computer or mobile device.

Discovering Computers 2018

3
1.0 Definition – Programming Language
§ Or
• A programming language is a set of rules, words, symbols,
and codes used to write computer programs.

• A programming language is a notational system for


describing tasks / computations in a machine-readable and
human-readable form.
Louden

4
Important Theory
Two types of programming language and the differences

1. Low-level language is a programming language that is machine dependent that


runs on only one particular type of computer.

2. High-level language is a programming language that is machine independent


that uses a series of English-like words to write instructions.

Low Level Language High Level Language


Machine dependent runs on only one type Machine independent runs on many
of computer and programs are not easily different types of computers and operating
portable to other types of computers. systems and the programs are easily
portable to other types of computers.
The language or code is difficult to learn The language or code is easy to learn
because it uses binary digits (1,0) and because it uses series of English like words
symbolic instruction codes. to write instructions.
The language or code is nearer to machine The language or code is nearer to human
language (using bit and bytes (1,0) ) language (English like statement)
Important Theory
Two types of Low Level Languange:- Machine language and
Assembly languange
§ Pro’s and Con’s between two types of Low Level language
MACHINE LANGUAGE ASSEMBLY LANGUAGE
Definition: Definition:
First generation of programming languages that Second generation of programming
use a series of binary digits (1s and 0s) and languages where instructions are written
hexadecimal digit (combination of numbers and using symbolic instruction codes which
letters that represents binary digits) are meaningful abbreviations.
Advantages Advantages
•Instructions are readily understood by the •Instructions are easier to learn compared to
computer machine language because it using the
•Ready for immediate execution symbolic instruction codes.
Disadvantages Disadvantages
•Instructions are extremely cryptic (not straight •Not readily understood by computer, thus
forward) and difficult to learn need to be translated to machine language
•Machine-dependent; runs on only one type of •Machine-dependent; runs on only one type
computer. of computer.
•Not portable to other types of computers. •Not portable to other types of computers.
Definition – Programming Paradigm
§ What is the Programming Paradigm?
§ A programming paradigm is a style, or “way,” of programming.
• A programming paradigm is a fundamental style of
computer programming, that is can be categorized
according to the approach used to solve a problem.
OR
• A programming paradigm is an approach to programming a
computer based on a mathematical theory or a coherent set
of principles.
• A paradigm, therefore, is a way in which computer language
looks at the problem to be solved.

7
Programming Paradigm
§ Three types of Paradigm in Programming?

1. Procedural 2. Object oriented programming

3. Logic

8
Programming Paradigm : Procedural
• procedural programming organizes the
program code into procedures (or
functions or methods).

• program starts with a problem and then


breaks that problem down into smaller
sub-problems or sub-procedures. (it
divides a program code into a collection
of procedures and data)

• procedural programming is also known as


imperative programming.

• Cons: sometimes difficult to locate and


edit all related elements in the program.
Programming Paradigm : Object Oriented (OOP)
• programming paradigm that uses
classes and objects to create models
based on the real world environment.

• it easy to maintain and modify existing


code as new objects are created
inheriting characteristics from existing
ones.

• ease of development and ability for


other developers to understand the
program after development

• is an efficient and effective language /


paradigm
Programming Paradigm : Logic
• uses automated reasoning to compute • use predicates instead of
over a set of facts and rules. Program functions to assign rules. This
code is written using logic notation. gives more flexibility because
Programs are executed by applying relations treat arguments
inference rules over these facts until an and answers in the same
answer to the problem is found way.
(facts + rules).
• can effectively make conclusions based “ declaring what you want and
on a question. letting the execution engine drive
the results. “
Important Theory
Differences between three types of paradigms
DIFFERENCE BETWEEN PROCEDURAL VS OBJECT ORIENTED VS LOGIC

PROCEDURAL OBJECT ORIENTED LOGIC


Program is divided into a Program is divided into Program focusses on
collection of procedures small parts called objects predicate logic, in which the
(functions or methods) and basic concept is a relation.
data.
Eg: C, FORTRAN, PASCAL, Encapsulation of data and Eg: Prolog (programming -
BASIC, ALGOL processes eg: C#,C++, Java, logic), Strawberry Prolog,
Toon Talk
Differences between Procedural, Object-oriented,
and Logic-oriented Programming Paradigm
Procedural Object-oriented Logic-oriented

Program is divided into a Object-oriented programming divides The logic programming


collection of procedures a programming task into objects with paradigm uses automated
(functions or methods) and each object encapsulating its own reasoning to compute over a set
data. data and methods of facts and rules

Example : Example : Example :


main() class Circle { The program is to find whether
{ private int radius;
int radius; 3 is a whole number.
public void setRadius(int r) {
cout << “Area of circle is “ << radius = r; } All integers are whole numbers.
getArea(4);
} public double getArea() { (rules)
double area; 3 is an integer. (fact)
double getArea(int r) { area = 3.142 * radius * radius;
double area; return area; }
area = 3.142 * r * r; } Answer : Yes
return area; class FindCircle {
} public static void main() {
Circle circle1;
circle1.setRadius(4);
cout << “Area of circle is” <<
circle1.getArea(); }
Definition – Language Translator

§ What is a Translator?
• A translator is defined as a computer program
that converts instructions (source program)
written in one programming language to be
translated to machine language.

§ Three types of translator:


i. Assembler (ASM, MASM, LEASM) Low level languange

ii. Interpreter (Perl, PHP, Ruby)


High level languange
iii. Compiler (JAVA, C, C++)
15
Translator
Translator Description

Assembler A program that translates a program


written in assembly language into an
equivalent program in machine
language.
Interpreter A language translator that converts
program statements line by line into
machine language, immediately
executing each one.

Compiler A language translator that converts an


entire program into machine language
before executing it.

16
are programs that translate
high level language into machine language

High Level Machine


into
Language Language

Source Code Object Code


(High Level Language) (Machine Language)

10 Input “Number 1” ; x 0010001 010010 0000100


20 Input “Number” ; y 0001001 001000 0010000
30 z=x+y 0010001 010010 0000001
40 Print “Answer “ ; z 0010011 010101 1010101
1010 1001001 100101
MACHINE LANGUAGE
1 1110111 000110

ASSEMBLY LANGUAGE

ASSEMBLER
HIGH LEVEL LANGUAGE
IF MARKS > 50 THEN

INTERPRETER PRINT “LULUS”


ELSE
PRINT “GAGAL”
COMPILER END IF
Important Theory

Differentiation between 3 types of translator in computer


programming
Translator Assembler Interpreter Compiler
Description Converts programs Executes other programs Converts an entire high
written in assembly directly, running through level language program
language to machine program code and into machine language
language executing it line-by-line. before executing it.
Examples: GAS, FAP, Examples: BASIC, PHP, Java COBOL, COBRA, C++, C,
COMPASS Java
Advantage Easier to debug(check Runs faster
errors) than a compiler.
Disadvantage Interpreters are generally Cannot change the
slower than compiled program without going
programs due to the per- back to the original source
line translation method code
Summary
• Define programming language.
• Define programming paradigm.
• Define language translators
A programming language is a set of words, abbreviations, and symbols
that enables software developer / programmer to communicate
instructions to a computer or mobile device

•A translator is defined as a •A programming paradigm is a


computer program that converts fundamental style of computer
instructions (source program) programming, that is can be
written in one programming categorized according to the
language to be translated to approach used to solve a
machine language. problem.

21

You might also like