[go: up one dir, main page]

0% found this document useful (0 votes)
21 views40 pages

L1 - Programming Languages

Uploaded by

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

L1 - Programming Languages

Uploaded by

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

PROGRAMMING

LANGUAGES
By Sir. Joshua
Introduction
 Computer program is a set of instructions that guide
a computer hardware to accomplish a specific task.
 The act of creating a program is known as
programming.
 When you write a computer program, you are
instructing the computer what to do and how to do
it.
 In order to create computer programs, you need a
special language to instruct the computer.
 Languages used to program the computer are
known as programming languages.

 There are many types of programming languages such as C,
C++, C#, Java, JavaScript, Python, Ruby, and Visual Basics.
 Programmers use programming language to construct
programs which are later commanded by a user to
accomplish a certain task.
 Before creating programs, programmers should follow a
number of steps that are related to problem solving.
 These steps comprise:
1. Defining and analysing the problem,
2. Designing or planning the solution,
3. Coding the program,
4. Testing and debugging the program
5. Documenting
Important terms used in
programming language
Source code
 A source code, also known as codes, is a collection of
computer instructions written by a programmer in a
high-level or intermediate programming language.
 It may include comments to aid with reasoning and
maintenance of a program.
 The source code may be written in C++, Java,
Python, PHP and other languages.
 A source code is machine independent.

Object code
 An object code is a machine-readable code
in a binary format (0s and 1s) that is
obtained after converting source code.
 The object code is also known as machine
code because it can only be read and
understood by the processor.

Translators
 Translators are programming language
processors required to change a program
into the machine-readable languages.
 There are three main categories of
translators namely assemblers,
interpreters and compilers.
Background to computer
programming languages
 Historically,
computer programming
languageshave passed through five (5)
generations.
 These generations can be divided into two
levels of programming languages:
 Low-level programming languages
 High-level programming languages
Low-level programming
languages
 Low level programming languages are
characterized by little effort to translate
programs into machine readable forms.
 They are not portable; hence, they are not easy
to be transferred from one computer to another.
 Thereason for importability is due to the fact
that only the same processor of a particular
manufacturer that a language was designed for
can read the codes written in that computer for
processor to translate

 These languages are machine dependent,


and they do not require any compiler to
translate them to machine codes.
 Examplesof low level programming
languages include machine languages and
assembly languages.
Advantages of low-level programming
languages
 Programs designed by using low levelprogramming languages
require less memory to be executed. For that case, they run fast.
 Low-level languages do not need compilers or interpreters to
change into machine readable form.
 Since a low-level language is closely related to a machine
language, it provides direct interaction with the internal memory
of the computer.
 Low-level programming languagesprovide a conducive
environment for utilising a processor.
 There is direct communication between hardware parts and
lowlevel programming languages.
Disadvantages of low-level
programming
languages
 Low-level languages need high expertise in
programming to design a program.
 The programs created with low-level language are not
portable simply because they cannot be transferred
from one hardware or software to another.
 Low-level programming languageshave challenging
environment for developing and executing programs.
 Using and learning low-level languages is not easy
compared to high-level languages.
 It is complicated to debug errors in low-level languages
High-level programming
languages
 High-level languages are machine independent.
 Thismeans that, the execution of the program
designed by high level language does not interfere
with the normal operation of the computer system.
 Unlikelow-level languages, high-level languages
are closely related to human languages and not
machine language.
 Examples of high-level programming
languagesinclude Pascal, Fortran, COBOL, C, C++,
Java, JavaScript, Visual Basics and Python.
Types of high-level languages
Commercial languages
 These are programming languages used for commercial
purposes such as COBOL (Common Business Oriented
Language).
Scientific languages
 These are programming languages used for engineering
and scientific purpose, such as FORTRAN (FORmula
TRANslation).
Multi-purpose languages
 These are programming languages required to perform
different tasks. Examples include C, C++, Java, JavaScript
and Python.

Special-purpose languages
 These are programming languages intended to be
used for a specific purpose such as air traffic control
and space technology. Examples include Ada, and
database language Structured Query Language (SQL).
Command languages for the operating system
 These are programming languages created to
communicate with the operating system and control
operations within the computer system. An example
of command languages, for operating system is Shell
language within UNIX operating system.

Scripting languages
 These are programming languages that do not need to be
translated into machine code before running. This means,
compilation is not required to execute scripting languages. Most
scripting languages are used to design and activate web pages.
Examples of scripting languages are JavaScript, VBScript, PHP,
Perl, Python and Ruby.
Procedural programming languages
 These programming languages divide a program into blocks of
codes known as structured programs. They design a program in a
sequence of steps or procedures made by a systematic
arrangement of functions, commands, and variables to accomplish
a particular task. Examples of procedural programming languages
are Pascal, BASIC, C, FORTRAN and COBOL

Object-Oriented programming language
 These are programming languagesmade by
many functional blocks known as objects. Each
object contains instructions similar to
procedural programming. Objectoriented
programming is characterized by
polymorphism, encapsulation and inheritance.
Examples of object-oriented programming
languages are C++, C#, Java, JavaScript,
VisualBasic.Net and Python.
Advantages of high-level
programming languages
 High-level languages provide an easy way to recognize
programs prone to errors.
 High-level languages are machine independent, and they
are portable programming languages that can easily be
transferred from one device to another.
 High-level languages provide a conducive environment for
developing, executing, and maintaining a program.
 High-level languages provide an easy way to learn and use
them.
 Since high-level languages run on different platforms, they
are widely used for programming.
Disadvantages of high-level
programming languages
 The program which is developed by high-level languages
must be interpreted or compiled to change it into machine-
readable form.
 They are not fast as they require timeto change a program
from a source code to an object code.
 They overload the processor by using several typed
statements, hence, slowing the computer’s processing
speed.
 They need enough memory to be maintained and executed.
Since highlevel languages are not practiced in machine
codes, they have no direct interaction with the hardware
device.
Generations of programming
languages
 In generations of programming languages,
low level languages are grouped in two
generations namely first generation and
second generation, while, high-level
languages can be grouped into three
generations, namely third, fourth and fifth
generation.
 Therefore,
there are five generations of the
programming languages as follows:
First generation computer
programming (Machine language)
 Time Period: Late 1940s - Early 1950s
 The first-generation languages are also called machine
languages/ 1G language.
 The machine language statements are written in binary code
(0/1 form) because the computer can understand only binary
language.
 It directly interacts with the hardware, which makes it very
efficient but difficult for humans to write and understand.
 Each instruction is specific to the architecture of the
machine, hence it is machine-dependent.

Key Characteristics:
 Instructions are written in binary format.
 No translation required, as the code is directly
executed by the computer.
 Complex and error-prone for humans to write.
Example:
For an Intel processor, machine language code might look
like this:
Advantages and Disadvantages
Advantages:
 Fast & efficient as statements are directly
written in binary language.
 No translator is required.
Disadvantages:
 Difficult to learn binary codes.
 Difficult
to understand – both programs &
where the error occurred.
Second generation computer
programming (Assembly language)
 Time Period: Early 1950s - Late 1950s
 The second-generation languages are also called assembler
languages/ 2G languages.
 Assembly language contains human-readable notations that can
be further converted to machine language using an assembler.
 Assembler – converts assembly level instructions to machine-
level instructions.
 Programmers can write the code using symbolic instruction
codes that are meaningful abbreviations of mnemonics
(symbolic representations).

Key Characteristics:
 Requires an assembler to convert the code into
machine language.
 More readable than machine language but still
hardware-specific.
Example

 Here, commands like MOV and ADD correspond to low-


level CPU operations but are easier to read than binary.
Advantages and Disadvantages

Advantages:
 Itis easier to understand if compared to machine
language.
 Modifications are easy.
 Correction & location of errors are easy.
Disadvantages :
 Assembler is required.
 This language is architecture /machine-dependent,
with a different instruction set for different machines.
Third generation programming
languages
 Time Period: Late 1950s - 1970s
 The third generation is also called procedural language /3
GL.
 It consists of the use of a series of English-like words that
humans can understand easily, to write instructions.
 For execution, a program in this language needs to be
translated into machine language using a Compiler/
Interpreter.
 Examples of this type of language are C, PASCAL,
FORTRAN, COBOL, etc

Key Characteristics:
 Higher abstraction from hardware.
 Easier to write and debug.
 Supports structured programming.
Examples:

FOTRAIN and C “Hello World” codes examples.


Advantages and Disadvantages
Advantages:
 Use of English-like words makes it a human-
understandable language.
 Lesser number of lines of code as compared to the
above 2 languages.
 Same code can be copied to another machine &
executed on that machine by using compiler-specific to
that machine.
Disadvantages:
 Compiler/ interpreter is needed.
 Different compilers are needed for different machines.
Fourth generation programming
languages
 Time Period: 1970s - 1990s
 The fourth-generation language is also called a non –
procedural language/ 4GL.
 Fourth-generation languages are more focused on simplifying
tasks such as database manipulation, report generation, and
data analysis
 They allow users to specify what they want to accomplish,
not how it should be done (declarative style).
 Examples: C++, PHP, JavaScript, SQL, MatLab, Foxpro, Focus,
etc.
 These languages are also human-friendly to understand.

Key Characteristics:
 High abstraction from hardware.
 Often domain-specific, focused on reducing
development time.
 Simplified syntax and built-in functionalities.

Examples:
Advantages and Disadvantages
Advantages:
 Easy to understand & learn.
 Less time is required for application creation.
 It is less prone to errors.
Disadvantages:
 Memory consumption is high.
 Has poor control over Hardware.
 Less flexible.
Fifth generation programming
languages
 Time Period: 1990s – Present
 The fifth-generation languages are also called 5GL.
 It is based on the concept of artificial intelligence.
 It uses the concept that rather than solving a problem
algorithmically, an application can be built to solve it based on
some constraints, i.e., we make computers learn to solve any
problem.
 These languages are designed to let computers solve problems on
their own with minimal human intervention.
 Parallel Processing & superconductors are used for this type of
language to make real artificial intelligence.
 Examples: PROLOG, LISP, etc.

Key Characteristics:
 Focus on logic, inference, and constraints.
 Used in AI, neural networks, machine learning, and
natural language processing.
Examples:
Advantages and Disadvantages
Advantages:
 Machines can make decisions.
 Programmer effort reduces to solve a
problem.
 Easier than 3GL or 4GL to learn and use.
Disadvantages:
 Complex and long code.
 Moreresources are required & they are
expensive too.
Summary Table of Generations
Example
Generation Time Period Characteristics
Languages
Machine-level,
Late 1940s - Early
First Generation binary codes, Machine Code
1950s
hardware-specific

Second Early 1950s - Late Assembly language,


Assembly
Generation 1950s uses mnemonics
High-level,
hardware-
Third Generation Late 1950s - 1970s C, FORTRAN, COBOL
independent,
compiled
Very high-level,
SQL, MATLAB,
Fourth Generation 1970s - 1990s domain-specific,
Oracle Forms
declarative
Problem-solving, AI,
Prolog, LISP, Python
Fifth Generation 1990s - Present machine learning-
(AI/ML libraries)
focused
Errors in computer
programming
 Thereare four common errors that may
occur when someone write a computer
program.
 Theseare syntax errors, semantic errors,
logical errors, and run-time errors.
Syntax errors
(compile-time errors)
 Itis defined as a mistake in the spelling,
punctuation or order of words in a program.
 These errors are also called compile-time
errors.
 They normally happen when the
programmer fails to follow language syntax
rules in the course of writing program.
For example: In C++ program, failure to put
semicolon at the end of the statement.
Semantic errors
(Exception errors)
 A semantic error is an error that relates to the meaning
of the code, particularly a mistaken idea of how the
compiler interprets the code.
 Semantic errors are typically syntactically valid, but they
are inconsistent in their meaning or they are invalid.
 For example: misunderstanding how a particular
function works and using it incorrectly.
 Semantic errors happen when the statements written in
the program cannot be well interpreted by the compiler
Run-time errors
(Exception errors)
 Run-time errors are the types of errors that occur during
program execution (run-time) after successful compilation
of the program.
 Division by zero is one of the most common run-time errors.
 In this type of errors, the compiler does not directly point to
the line where the error occurs.
 Run-time errors are also called “bugs”.
 Before a program is released to the market, commercial
software are normally checked to examine the process of
bugs during the debugging process.
Logic errors
 Thelogical errors may occur even if the program is
syntactically correct and does something.
 The program might be running without crushing.
 However, the output of the program will be
different from what was intended by the writer of
the program.
 Example of a logical error is when a program uses
a wrong formula, or assigns wrong value to the
code assignment statements.

You might also like