0% found this document useful (0 votes)
7 views

Chapter 1 Reminder On Imperative Programming

Uploaded by

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

Chapter 1 Reminder On Imperative Programming

Uploaded by

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

Programmation Orientée Objet.

Ch1 : Rappels Génie Logiciel Enseignant : Kadache Nabil

Chapter 1. Reminder on imperative programming.

1.1- Définitions
 Software:

Software or an application is a set of programs and documents, which allow a computer


system (hardware, software and users) to perform a particular task or function (example:
accounting software, loan management software) .

Software, depending on its size, can be developed by a single person, a small team, or a set of
coordinated teams. The development of large software by large teams poses significant design
and coordination challenges. However, the development of software is an absolutely crucial
phase which monopolizes most of the cost of the software and conditions its success and its
durability.

 Software Engineering :

Software Engineering is the field of 'engineering sciences' whose purpose is the design,
manufacture and maintenance of complex, secure and quality software systems ('Software
Engineering' in English). Today the economies of all developed countries are dependent on
software systems.

The concept of software engineering appeared at the end of the 1960s during a NATO
conference after the following observations in software development:
 Increase in costs;
 Difficulties in maintenance and development;
 Unreliability;
 Failure to meet specifications and deadlines.

 Software process :

A software process is a set of activities whose purpose is to build a software product. New
software is increasingly developed by extending and modifying existing (legacy) systems.

Software processes are complex processes that involve judgments and decisions.
Activities common to software processes:
- Specification: definition of functionality and constraints related to software
- Design and implementation: software production
- Validation: checking whether the software produced meets the customer's requirements.
- Evolution: Follow the change of the customer's needs.

 Software quality:

There are several quality criteria for software;


– Validity: ability of software to perform exactly the tasks defined by its specification,
– Reliability: ability of software to continuously provide the expected service,
– Robustness: ability of software to operate even under abnormal conditions,
– Extensibility: ease of adapting software to specification changes,

1
Programmation Orientée Objet. Ch1 : Rappels Génie Logiciel Enseignant : Kadache Nabil

– Reuse: ability of software to be reused in whole or in part,


– Compatibility: ability of software to be combined with each other,
– Efficiency: ability of software to make good use of hardware resources such as memory,
CPU power, etc.
– Portability: ease of being ported to new hardware and/or software environments,
– Traceability: ability to identify and/or follow an element of the specifications linked to a
software component,
– Verifiability: ease of preparation of acceptance and certification procedures,
– Integrity: ability of software to protect its various components against unauthorized access
or modification,
– Ease of use, maintenance, etc.
These criteria are sometimes contradictory, the choice of compromises must be made
according to the context.

1.2- Programming paradigms

A paradigm is a way of approaching computer programming by dealing with a certain way the
solutions to the problems.
Programming paradigms classify programming languages according to of their characteristics.
A programming paradigm offers the developer a way to think about his program and therefore
conditions the possible solutions to a problem that the developer needs to solve. Thus, two
languages following two programming paradigms find two different solutions to the same
problem.

As illustrated in the following figure, there are two major programming paradigms:
imperative and declarative.

1.2.1 Imperative programming paradigm

It is one of the oldest programming paradigm. It is based on Von Neumann architecture and
works by changing the program state through assignment statements. It performs step by step
task by changing state. The main focus is on how to achieve the goal. The paradigm consist of
several statements and after execution of all the result is stored.
Advantages:
1. Very simple to implement

2
Programmation Orientée Objet. Ch1 : Rappels Génie Logiciel Enseignant : Kadache Nabil

2. It contains loops, variables etc.


Disadvantage:
1. Complex problem cannot be solved
2. Less efficient and less productive

I. Procedural programming.
This paradigm emphasizes on procedure in terms of under lying machine model.
There is no difference in between procedural and imperative approach. It has the
ability to reuse the code and it was boon at that time when it was in use because of its
reusability.
Example (In C language)
int i ;
int sum=0 ;
int arr={5,6,1,23,58,14} ;
for (i=0 ;i<arr.length ;i++)
sum = sum + arr[i];
printf(“The sum of the elements of arr is:%d \n”,sum}

Result:
The sum of the elements of arr is: 107

II. Object oriented programming.


The program is written as a collection of classes and object which are meant for
communication. The smallest and basic entity is object and all kind of computation is
performed on the objects only. More emphasis is on data rather procedure. It can
handle almost all kind of real life problems which are today in scenario.
Advantages:
 Data security
 Inheritance
 Code reusability
 Flexible and abstraction is also present

Examples of languages that support Object Oriented programming paradigm:

Simula : first OOP language


Java : developed by James Gosling at Sun Microsystems
C++ : developed by Bjarne Stroustrup
Objective-C : designed by Brad Cox
Visual Basic .NET : developed by Microsoft
Python : developed by Guido van Rossum
Ruby : developed by Yukihiro Matsumoto
Smalltalk : developed by Alan Kay, Dan Ingalls, Adele Goldberg.

The following Java code illustrates the defintion of the Student class:

3
Programmation Orientée Objet. Ch1 : Rappels Génie Logiciel Enseignant : Kadache Nabil

III.
public class Student {
III.
private String firstname;
III.
private String lastname;
III.
private int year;
III.
public Student(String firstname, String Lastname) {
III.
this.firstname=firstname;
III.
this.lastname=lastname;
III.
}
III.
public String getFullname() {
III.
return firstname+” “+lastname;
III.
}
III.
public setFirstname(String firstname)
III.
this.firstname=firstname;
III.
}
III.
public setLastname(String Lastname)
III.
this.lastname=lastname;
III.
}
III.
public static void main(String args[]) {
III.
Student std1=new Student(“James”,”Gossling”);
III.
System.ou.println(“My name is ”+std1.getFullname);
III.
std1.setFirstname(“Dennis”);
III.
std1.setLastname(“Ritchie”);
III.
System.ou.println(“Now, my name is ”+std1.getFullname);
III.
}
III.
III.
Result:
III.
My name is James Gossling
III.
Now, my name is Dennis Ritchie
III.
III.
III.
Structured programming.
Structured programming is a subset of imperative programming. It is an important
programming paradigm, which appeared around 1970. It consists of small fragments
of code with a well-defined structure. The most representative example of this style of
programming is the famous SQL (Structured Query Language) used to manage
databases.
Example (in SQL)

SELECT *
FROM STUDENT
WHERE Year=2024

1.2.2 Declarative programming paradigm

In declarative programming, we describe the “what to do” without to specify the “How to do
it”, i.e. the problem. For example, HTML pages are declarative because they describe what a

4
Programmation Orientée Objet. Ch1 : Rappels Génie Logiciel Enseignant : Kadache Nabil

page contains (text, headings, paragraphs, etc.) and not how to display them (positioning,
colors, fonts, etc.). Imperative programming (e.g. C or Java), on the other hand, describes the
how, i.e. the control structure corresponding to the solution.

This is a form of programming with no side-effects, and generally corresponds to


mathematical logic.

There are several forms of declarative programming:

I. Logic programming.
In this programming sub-paradigm, the components of an application are logical
relationships, An example of language that use such programming style is Prolog:

parent (paul,jean) .
parent(jean,anne).
parent(jean,anne).
parent(anne,marie).

homme(paul).
homme(jean).

pere(X,Y) :- parent(X,Y), homme(X).

grand_pere(X,Y) :- pere(X,Z), parent(Z,Y).

II. Functionnal programming.


functional programming, which perceives applications as a set of mathematical functions,
such as Lisp, Caml, Haskell and Oz; The following example illustrates a function that
calculates the factorial of a number in LISP, the function is implemented in a recursive
manner

(defun factorial (n) (if (<= n 1) 1 (* n (factorial (-


n 1)))))

1.2- Conclusion.

There are several programming paradigms, Current programming languages are generally
multi-paradigm; This means that the same language supports several paradigms at the same
time. For example, the C language supports both procedural and functional paradigms; C++
supports procedural, functional and object-oriented paradigms.

You might also like