Register to get access to free programming courses with interactive exercises

Declarative approach Python: Declarative programming

We can write almost any code in any language in different ways. You can split the code into functions differently, name variables in different ways, or change the nesting depth of conditional constructs. These are all metrics of code quality and the individual components that make coding style.

However, coding style has almost no effect on the specific task and the solution architecture. We determine these properties by choosing the programming paradigm.

A programming paradigm is a set of ideas about how to solve a problem. We start applying the paradigm even before we start writing code. The code in a particular language merely allows us to write our thoughts in a program with a greater or lesser degree of convenience.

An experienced programmer knows how to:

  • Think in the right way and various paradigms
  • Apply different paradigms
  • Choose the right paradigm for specific tasks
  • Write their thoughts in code in different programming languages

We can say that the paradigm is suitable for any programming language when you don't need to battle with the language and change your approach to solve a problem. If the paradigm fits the language, the programmer writes down their thoughts as they are.

Python and most modern high-level programming languages are considered multiparadigms. In other words, you can use many different paradigms. It won't be any less convenient.

C and other low-level languages cannot afford this freedom because code in these languages must be efficient. In these languages, solutions are tied as much as possible to how the task is understood by the computer, not by the developer.

Imperative programming

Let's imagine that we need to solve a complex problem. We cannot solve it in one computer action, so we describe a sequence of steps to be performed.

We break down the broad steps into smaller ones until the interpreter or compiler of the chosen language can understand each step. Simply put, we think through and describe how to achieve the desired result. This description of a sequence of steps is called imperative programming.

Imperative programming involves changing the state of the computer. Large programs constantly modify global and local variables:

  • Write things to the disk
  • Send and receive from the network

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing:">Bookmate</span>
<span class="translation_missing" title="translation missing:">Healthsamurai</span>
<span class="translation_missing" title="translation missing:">Dualboot</span>
<span class="translation_missing" title="translation missing:">Abbyy</span>
Suggested learning programs
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.