You are on page 1of 17

Programming languages

Introduction
Definitions

A programming language
a formal notation for specific computations, independent of a
specific machine
Set of imperative commands used to direct a computer to
perform specific tasks.
A program is a sequence of sentences written according
to this notation and it can be executed to perform a
coputation
A computation is a processing operation over some
data
Data are representations of information
Programming paradigms

Programming paradigms
A fundamental style of computer programming, serving as a
way of building the structure of and elements of computer
programs
are the result of different ideas about how programs should be
constructed
Imperative programming
Imperative programming – is a coputer paradigm that
describes computation as a series of actions defined by
statements that change a program state
A program state is defined by the contents of the computer
memory
A statement is an instruction for the computer to execute

Elements of imperative programming


Sequences of commands
Explicit state transitions
Update by assignment

Examples: C, Java, Pascal, Fortran, Basic


Imperative programming
Example:

#include <stdio.h>

int main()
{
printf("Hello world\n");
return 0;
}
Declarative programming
Declarative programming is a programming
paradigm that describes computation in terms of
desired results, without explicitly listing commands or
steps that must be performed
It comprises several other programming paradigms:
Functional programming
Logical programming

Examples: SQL, Prolog, Lisp, CSS


Declarative programming
Example:

<style>
h1 {
text-decoration: overline;
}

h2 {
text-decoration: line-through;
}

h3 {
text-decoration: underline;
}
</style>
Functional programming
Functional programming is a programming
paradigm that describes computation as the
evaluation of mathematical functions and avoids state
changes
Definitory elements:
Pure expression evaluation
No assignments
Formula recurssion

Examples: Lisp, Scheme, ML


Functional programming
Example:

(defun square (x)


(* x x))

(defun add (x y)
(+ x y))
Logic programming
Logic programming is a programming paradigm
that describes computation as a set of logical
sentences
It is based on formal logic

Examples: Prolog
Logic programming
Example:
has(jack,apples).
has(ann,plums).
fruit(apples).
fruit(plums).
?- has(jack,X). /* what has Jack? */
X = apples
?- has(ann,X),fruit(X). /* has Ann fruits? */
yes
Structured programming
Structured programming is a programming paradigm
based on the organization of statements in subroutines,
block structures and the use od simple control structures
such as “if-then-else”, “for” and “while” statements
Programs are composed of three control structures
Sequences – ordered statements or subroutines executed in
sequence
Selection – statements are executed based on the state of the
program (“if-then-else”)
Iteration – statements are executed repeatedly, until the program
reaches a certain state (“for”, “while”)
Examples: C, Pascal, Java
Structured programming
Example:
int main()
{
int n, i = 3, count, c;
scanf("%d",&n);
for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 ) break;
}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}
}
Procedural programming
Procedural programming is a programming
paradigm based on the concept of procedure call
A procedure
is a sequence of program instructures that perform a
pecific task
It can be seen as an independent computer program that
is used as one step in a larger program
Any procedure can be called at any point during a
program execution, including by other procedures or by
itself
Examples: C, C++, Java, Lisp, PHP
Object oriented programming
Object oriented programming is a programming
paradigm based on the concept of “objects”
It involves the identification of important concepts
and the use of objects to structure the way that these
concepts are embodied in a program
OOP is an iterative process based on associating
objects with components or concepts in a system
Objects – consist of functions and data accessible
only through a specific interface
Examples: C++, Java, Delphi, C#
Object oriented programming
Example:
public class Cube {
int length;
int breadth;
int height;
public int getVolume() {
return (length * breadth * height);
}
}

cubeObject.length = 4;
cubeObject.breadth = 4;
cubeObject.height = 4;
cubeObject.getvolume()
Multi paradigm programming
Multi paradigm programming refers to
programming languages that support more than one
paradigm
Example:
Octave/ Matab
Imperative
Structured
Procedural
OOP

You might also like