Chapter 1 Reminder On Imperative Programming
Chapter 1 Reminder On Imperative Programming
1.1- Définitions
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:
1
Programmation Orientée Objet. Ch1 : Rappels Génie Logiciel Enseignant : Kadache Nabil
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.
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
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
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
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.
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).
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.