Basic programming paradigms. Concept of programming paradigm Declarative and procedural memory


Rating: / 0
Details Views: 3084

Programming Paradigms

What is a paradigm anyway? We can say that this is a certain view of the phenomena of the surrounding world and an idea of ​​​​possible actions with them. In programming, a paradigm is usually understood as a generalization about how the work of a program should be organized.

Among other things, there are such programming paradigms as directive (structural), object-oriented and declarative (functional-logical). Many languages ​​support multiple programming paradigms. On the other hand, there are languages ​​focused exclusively on the implementation of one paradigm.

Structured programming

Some representatives: Fortran, Pascal, C.

A directive program prescribes how to achieve a result, describing steps step by step. Therefore, such programming is quite easy to understand.

In structured programming, the sequence of command execution depends entirely on the input data.

In directive programming, at one time there arose the concept of localizing part of the code into so-called subroutines (functions, methods), with their subsequent calling from different places in the main program. When called, a subroutine can be passed any data in the form of arguments; and the subroutine, in turn, can return the result (that is, the data obtained during its execution) to the main program.

Functional and Logic Programming

Representatives of functional languages: List, Haskell.

Representative of logical languages: Prolog.

A declarative program states (declares) what is to be achieved as a goal. The precise formulation of the problem is important. The programmer does not specify an algorithm to solve it.

Functional programming is based on the mathematical concept of a function that does not change its environment; This is the difference between functional programming and functions in structured languages. A function program consists of a collection of function definitions, which in turn represent calls to other functions and statements that control the sequence of calls. Each function returns some value to the function that called it, whose evaluation then continues; this process is repeated until the result is achieved.

In logic programming, programs are expressed as mathematical logic formulas, and the solution to a problem is achieved by deducing logical consequences from them.

Object-oriented programming

Representatives of object-oriented languages: C++, Java, Python.

Particular attention is paid to data that is represented in the program as objects. Objects interact with each other using a message passing mechanism. The programmer’s task is to implement objects such that when interacting with them, it will be possible to obtain the desired result.

OOP is designed to solve more complex and voluminous problems compared to directive programming.

OOP is based on concepts such as inheritance, polymorphism and encapsulation.

Encapsulation assumes that unimportant details of an object are hidden. An object, receiving any command, “knows” how to process it based on the class it belongs to.

All objects are instances of classes, which in relation to each other can act as a parent-child. Child classes inherit the properties of the parent. In the case when 100% inheritance is not required, so-called polymorphism comes to the rescue, which involves overriding methods of the parent class in child classes.

A programming paradigm is a set of ideas and concepts that determine the style of writing programs.

The imperative paradigm describes the computation process in the form of instructions that change the state of the program. An imperative program is very similar to imperative orders in natural languages, that is, it is a sequence of commands that the computer must execute. Based on the Turing-Post finite automaton model.

The first imperative languages ​​were machine codes - the native programming language of the computer. In these languages, the instructions were extremely simple, which reduced the load on computers, but made it difficult to write large programs. In 1954, the first “human” programming language appeared - FORTRAN, then ALGOL, COBOL, BASIC, Pascal, C.

One of the characteristic features of imperative programming is the presence of variables with the “destructive assignment” operation. That is, there was a variable A, it had a value X. The algorithm instructs to assign the value Y to variable A at the next step. The value that A had will be “forgotten forever.”

Imperative programming is most suitable for implementing small subtasks, where speed of execution on modern computers is very important. In addition, working with external devices is usually described in terms of sequential execution of operations (“open the tap, draw water”), which makes such tasks ideal candidates for imperative implementation.

The choice of the framework of the imperative paradigm for teaching the basics of programming seems to be beyond doubt. There are several reasons for this:

· the imperative paradigm is closest to human nature and the intuitive concept of an algorithm in the early stages of thinking development (there is a positive experience of developmental education with elements of algorithmization already in elementary school);

· programming within the framework of the imperative paradigm is effective for a wide class of tasks, many of which fall within the zone of proximal development of students in the senior grades of basic school;

· the imperative paradigm is closest to the nature of a computer, the basic principles of its operation, since, despite all the complexity of a modern computer, at the hardware level it can still be considered as some kind of automaton (processor + memory + ...) with a finite set of states (contents) memory);

· the share of software products created exclusively within the framework of the declarative programming paradigm is small; As a rule, when solving problems, a combination of paradigms is used, one of which is imperative;

· a large selection of programming systems in the form of independent software and in the form of subsystems integrated into other systems, allowing the development of software products using the imperative paradigm;


· an extensive range of educational, reference and other publications on relevant programming systems in paper and electronic forms on various media and on the global network.

Disadvantage: in its pure form it allows solving only very simple problems.

Event-driven programming is programming in which the program's reactions to various events (user actions) are specified. PMS can be considered as a “descendant” of the imperative paradigm. SUP has 2 subclasses:

1.Parallel programming represents a program as a set of communicating processes that can be executed in parallel. Such programs can be executed either on one processor (alternating the execution of steps of each process) or on several.

In a parallel process system, each individual process processes events. Events can be either general for the entire system or individual for one or several processes. In such terms it is quite convenient to describe, for example, elements of a graphical user interface, or the modeling of any real processes (for example, traffic control) - since the concept of an event is natural for such tasks.

2.Object-oriented programming is a programming technology in which a program is viewed as a set of objects and their interactions. Every program object is an instance of some class; - classes can inherit the attributes and methods of their parent classes, while adding their own. The class hierarchy allows you to model the essence of the problem being solved at several levels of detail and then use a class that corresponds to the level of detail required to solve a specific subtask.

It is important to highlight the following basic properties of objects:

1.) Since one object can influence another solely by sending messages to the latter, it cannot in any way directly work with the “interlocutor’s” own data, and, therefore, cannot violate their internal consistency. This property (data hiding) is commonly called encapsulation.

2.) Since objects interact solely through the exchange of messages, interlocutor objects may not know anything about the implementation of message handlers in their counterpart. Interaction occurs solely in terms of messages/events, which are fairly easy to bind to the domain. This property (a description of interaction solely in terms of the domain) is called abstraction.

3.) Objects interact exclusively by sending messages to each other. Therefore, if in any scenario of object interaction you replace an arbitrary object with another one capable of processing the same messages, the scenario will also be implementable. This property (the ability to replace an object with another object with a similar class structure) is called polymorphism.

Many modern languages ​​support OOP, although to varying degrees: Purely object-oriented languages, such as Smalltalk and Ruby, are designed to support and even enforce an object-oriented development style, and do not support other programming styles; - predominantly object-oriented languages, such as Java, C++ and Python, are designed primarily to support OOP, but allow the use of elements of procedural programming; - Historically, procedural languages, for example, Perl and Fortran 2002, have been refined and support for some OOP elements has been added.

The declarative programming paradigm defines the computation process by describing the logic of the computation itself, rather than the control logic of the program.

Declarative programming is the opposite of imperative programming; the first describes what needs to be done, and the second describes exactly how to do it.

The most important types of declarative programming are functional and logical (or relational) programming.

1.Functional programming is one of the alternatives to the imperative approach. It is based on Church's lambda calculus. In imperative programming, algorithms are descriptions of sequentially executed operations. There is the concept of a "current execution step" (that is, time), and a "current state" that changes over that time.

There is no concept of time in functional programming. Programs are expressions; program execution consists of evaluating these expressions.

Since the order in which subexpressions are evaluated does not matter, functional programming can be implemented naturally on platforms that support parallelism.

Functional programming, like other "non-imperative" programming models, is usually used to solve problems that are difficult to formulate in terms of sequential operations. Almost all tasks related to artificial intelligence fall into this category. Among them, it is worth noting the tasks of image recognition, communication with the user in natural language, implementation of expert systems, automated theorem proving, and symbolic calculations. These tasks are far from traditional application programming, so they are not given much attention in computer science curricula.

Logic programming

In functional programming, programs are expressions, and their execution consists of calculating their value. In logic programming, a program is a theory (described in a fairly limited language) and a statement that needs to be proven. The proof of this statement will consist of the execution of the program.

Logic programming and the Prolog language emerged from research in the field of natural language analysis. Subsequently, it was discovered that logic programming is just as effective in implementing other artificial intelligence tasks.

Logic programming allows for natural parallel implementation.

It turned out that those paradigms that previously made their way into the light with sweat and blood through hordes of adherents of traditional methods are gradually forgotten. These paradigms arose at the dawn of programming and why they arose, what advantages they provided and why they are still used is still useful for any developer to know.

OK. The introduction is a lot of fun, but you don’t read it anyway, so if anyone is interested, welcome to the cut!

Imperative programming



Historically, the vast majority of computer technology that we program has a state and is programmed by instructions, so the first programming languages ​​were mainly purely imperative, i.e. did not support any paradigms other than the imperative one.

These included machine codes, assembly languages, and early high-level languages ​​like Fortran.

Key points:

In this paradigm, computation is described in the form of instructions that change the state of the program step by step.

In low-level languages ​​(such as assembly language), state can be memory, registers, and flags, and instructions can be those instructions that the target processor supports.

In higher-level ones (such as C), the state is only memory; instructions can be more complex and cause memory to be allocated and deallocated as they operate.

In very high-level ones (such as Python, if you program it imperatively), state is limited to only variables, and commands can be complex operations that would take hundreds of lines in assembly language.

Basic concepts:

- Instructions
- State

Generated concepts:

- Assignment
- Transition
- Memory
- Index

As main:
- Assembly languages
- Fortran
-Algol
-Cobol
-Pascal
-C
- C++
-Ada
As an auxiliary:
- Python
- Ruby
- Java
- C#
-PHP
- Haskell (via monads)

It is worth noting that most modern languages ​​support imperative programming to one degree or another. Even the pure functional language Haskell can be written imperatively.

Structured programming



Structured programming is a programming paradigm (also commonly used as a development methodology), which was the first big step in the development of programming.

The founders of structured programming were such famous people as E. Dijkstra and N. Wirth.

The pioneer languages ​​in this paradigm were Fortran, Algol and B, later succeeded by Pascal and C.

Key points:

This paradigm introduces new concepts that combine commonly used patterns for writing imperative code.

In structured programming, we still operate with state and instructions, but the concept of a compound instruction (block), branch and loop instructions is introduced.

With these simple changes, it's possible to eliminate the goto statement in most cases, simplifying your code.

Sometimes goto does make the code more readable, which is why it is still widely used, despite all the claims of its opponents.

Basic concepts:

- Block
- Cycle
- Branching

Languages ​​supporting this paradigm:

As main:
-C
-Pascal
- Basic
As an auxiliary:
- C#
- Java
- Python
- Ruby
- JavaScript

Partially supported:
- Some macro assemblers (via macros)

Again, most modern languages ​​support the structural paradigm.

Procedural programming



Again, the increasing complexity of software forced programmers to look for other ways to describe calculations.

Actually, additional concepts were once again introduced that allowed us to take a fresh look at programming.

This concept this time was procedure.

As a result, a new methodology for writing programs arose, which is welcomed to this day - the original problem is broken down into smaller ones (using procedures) and this happens until the solution to all specific procedures turns out to be trivial.

Key points:

A procedure is an independent piece of code that can be executed as a single instruction.

In modern programming, a procedure can have multiple exit points (return in C-like languages), multiple entry points (using yield in Python or static local variables in C++), have arguments, return a value as the result of its execution, be overloaded in number, or type of parameters and much more.

Basic concepts:

- Procedure

Generated concepts:

- Challenge
- Arguments
- Return
- Recursion
- Overload

Languages ​​supporting this paradigm:

As main:
-C
- C++
-Pascal
- Object Pascal
As an auxiliary:
- C#
- Java
- Ruby
- Python
- JavaScript

Partially supported:
- Early Basic

It's worth noting that several entry points from all of these languages ​​are only supported in Python.

Modular programming



Once again the increasing complexity of programs forced developers to share their code. This time the procedures were not enough and this time a new concept was introduced - a module.

Looking ahead, I will say that modules also turned out to be unable to contain the growing complexity of software at an incredible speed, and subsequently packages (this is also modular programming), classes (this is already OOP), and templates (generalized programming) appeared.

A program described in the modular programming style is a set of modules. What's inside, classes, imperative code or pure functions, doesn't matter.

Thanks to modules, serious encapsulation appeared in programming for the first time - it is possible to use any entities inside a module, but not show them to the outside world.

Key points:

A module is a separate named entity of a program that combines other program units that are similar in functionality.

For example, the List.mod file includes the List class
and functions for working with it - a module.

The Geometry folder containing the Shape, Rectangle and Triangle modules is also a module, although some languages ​​separate the concept of a module and a package (in such languages ​​a package is a set of modules and/or a set of other packages).

Modules can be imported (connected) in order to use the entities declared in them.

Basic concepts:

- Module
- Import

Generated concepts:

- Plastic bag
- Encapsulation

Languages ​​supporting this paradigm:

As main:
- Haskell
-Pascal
- Python
As an auxiliary:
- Java
- C#
- ActionScript 3

Partially supported:
- C/C++

Some languages ​​introduce separate abstractions for modules, while others can use header files (in C/C++), namespaces, static classes, and/or dynamic link libraries to implement modules.

Instead of a conclusion

In this article, I did not describe the now popular object-oriented, generic and functional programming. Simply because I have my own, rather radical opinion on this matter and I did not want to start a holivar. At least for now. If the topic proves useful to the community, I plan to write several articles outlining the basics of each of these paradigms in detail.

Also, I did not write anything about exotic paradigms, such as automata, applicative, aspect/agent/component-oriented programming. I didn’t want to make the article very large, and again, if the topic is in demand, I will write about these paradigms, perhaps in more detail and with code examples.

(BASICS OF ALGORITHMIZATION AND PROGRAMMING)
  • Programming paradigms and technologies
    Objectives of Chapter 1. Study the concepts of “programming paradigm”, “programming technology”. 2. Get a general understanding of modern software development technologies. 3. Study the stages of creating a structural program. 4. Get acquainted with software development life cycle models...
  • SE programming paradigms
    SWEBOK includes a number of programming paradigms See: Lavrishcheva E. M. Assembly-type programming paradigms in software engineering // UKRProg-2014. No. 2-3. pp. 121-133. . Its programming bootcamps include the following: procedural programming(course CS1011 “Programming fundamentals”),...
    (SOFTWARE ENGINEERING AND TECHNOLOGIES FOR PROGRAMMING COMPLEX SYSTEMS)
  • PROGRAMMING PARADIGMS
    MODULAR PROGRAMMING. BASIC CONCEPTS One of the key problems of modern programming is the reuse of modules and components (KPI). They could be programs, subroutines, algorithms, specifications, etc., suitable for use in the development of new, more complex software....
    (SOFTWARE ENGINEERING. PARADIGMS, TECHNOLOGIES AND CASE TOOLS)
  • Procedural paradigm
    The procedural paradigm was chronologically first and prevailed for a long time. Currently, it is gradually giving way to the object-oriented paradigm, although it still occupies about half of the software development market. It is applied at all levels of software development...
    (ALGORITHMIZATION AND PROGRAMMING)
  • Declarative and procedural memory
    Another independent way of functional organization of memory, independent of others, is its division into declarative And procedural. These two methods of organizing memory have a completely understandable functional basis. A form of declarative memory is designed to support mental...
    (Psychology and pedagogy)
  • The general programming paradigms that emerged at the very beginning of the era of computer programming, including the paradigms of applied, theoretical and functional programming, are the most stable.

    Applied programming is subject to a problem orientation, reflecting the computerization of information and computational processes of numerical processing, studied long before the advent of computers. It was here that a clear practical result quickly emerged. Naturally, in such areas, programming is not much different from coding; for it, as a rule, the operator style of representing actions is sufficient. In the practice of applied programming, it is customary to trust proven templates and libraries of procedures and avoid risky experiments. The accuracy and stability of scientific calculations is valued. The Fortran language, a veteran of application programming, gradually began to yield somewhat in this area to Pascal, C, and on supercomputers to parallel programming languages ​​such as Sisal.

    Theoretical programming adheres to a publication orientation aimed at comparability of the results of scientific experiments in the field of programming and computer science. Programming tries to express its formal models, to show their significance and fundamental nature. These models inherited the main features of related mathematical concepts and established themselves as an algorithmic approach in computer science. The desire for evidence of constructions and assessment of their effectiveness, plausibility, correctness, correctness and other formalized relations in program diagrams and texts served as the basis for structured programming and other methods for achieving reliability in the program development process, for example, competent programming. The standard subsets of Algol and Pascal, which served as working material for programming theory, were replaced by more convenient applicative languages ​​for experimentation, such as ML, Miranda, Scheme, Haskell and others. Now they are joined by innovations in C and Java.

    Functional programming was formed as a tribute to the mathematical orientation in the research and development of artificial intelligence and the development of new horizons in computer science. An abstract approach to the presentation of information, a laconic, universal style of constructing functions, clarity of the execution environment for different categories of functions, freedom of recursive constructions, trust in the intuition of the mathematician and researcher, avoidance of the burden of prematurely solving unprincipled problems of memory allocation, rejection of unreasonable restrictions on the scope of definitions - - all this is linked by John McCarthy to the idea of ​​the Lisp language. The thoughtfulness and methodological validity of the first Lisp implementations made it possible to quickly accumulate experience in solving new problems and prepare them for applied and theoretical programming. Currently, there are hundreds of functional programming languages ​​focused on different classes of tasks and types of technical means.

    The main programming paradigms have evolved as the complexity of the problems being solved has increased. There has been a stratification of programming tools and methods depending on the depth and generality of the elaboration of the technical details of the organization of computer information processing processes. Different styles of programming have emerged, the most mature of which are machine-oriented, system, logical, transformational, and high-performance parallel programming.

    Machine-oriented programming is characterized by a hardware approach to organizing the operation of a computer, aimed at accessing any hardware capabilities. The focus is on hardware configuration, memory state, commands, control transfers, sequencing of events, exceptions and surprises, device response time and response success. Assembly language has been overshadowed for some time as the visual medium of choice by Pascal and C, even in microprogramming, but user interface improvements may regain its position.

    System programming has been developing for a long time under the pressure of service and custom work. The manufacturing approach inherent in such work relies on a preference for reproducible processes and stable programs designed for repeated use. For such programs, a compilation processing scheme, static analysis of properties, automated optimization and control are justified. This area is dominated by the imperative-procedural style of programming, which is a direct generalization of the operator style of applied programming. It allows for some standardization and modular programming, but it acquires rather complex structures, specifications, testing methods, program integration tools, etc. The stringent requirements for efficiency and reliability are met by the development of professional tools that use complex associative semantic heuristics along with methods of syntactically-driven design and program generation. The undeniable potential of such tools in practice is limited by the complexity of development - a qualification requirement arises.

    High-performance programming is aimed at achieving the maximum possible performance when solving particularly important problems. The natural reserve of computer performance is parallel processes. Their organization requires detailed consideration of time relations and a non-imperative style of managing actions. Supercomputers supporting high-performance computing required special systems programming techniques. The graph-network approach to representing systems and processes for parallel architectures has been expressed in specialized parallel programming languages ​​and supercompilers, adapted to map the abstract hierarchy of task-level processes onto the specific spatial structure of processors of real equipment.

    Logic programming arose as a simplification of functional programming for mathematicians and linguists solving symbolic processing problems. Particularly attractive is the possibility of using nondeterminism as a conceptual basis, which frees us from premature ordering when programming the processing of formulas. The production style of generating processes with returns is sufficiently natural for a linguistic approach to clarifying formalized knowledge by experts and reduces the starting barrier.

    Transformational programming methodologically combined the techniques of program optimization, macrogeneration and partial computation. The central concept in this area is information equivalence. It manifests itself in defining transformations of programs and processes, in searching for criteria for the applicability of transformations, in choosing a strategy for their use. Mixed calculations, deferred actions, lazy programming, delayed processes, etc. are used as methods for increasing the efficiency of information processing under certain additionally identified conditions.

    Extensive programming approaches are a natural response to radical improvements in the performance of hardware and computer networks. There is a transition of computing tools from the class of technical tools to the class of household appliances. The ground has emerged for updating approaches to programming, as well as the possibility of rehabilitating old ideas that were poorly developed due to the low technology and performance of computers. It is of interest to form research, evolutionary, cognitive and adaptation approaches to programming that create the prospect of rational development of real information resources and computer potential.

    A research approach with an educational-game style of professional, educational and amateur programming can give impetus to search ingenuity in improving programming technology that could not cope with crisis phenomena on the previous element base. The evolutionary approach with a mobile style of refining programs is quite clearly visible in the concept of object-oriented programming, which is gradually developing into subject-oriented programming. Reusing definitions and inheriting object properties can lengthen the life cycle of debugged information environments, increase the reliability of their operation and ease of use.

    A cognitive approach with an interoperable style of visual-interface development of open systems and the use of new audio-video tools and non-standard devices open up ways to enhance the perception of complex information and simplify its adequate processing.

    An adaptive approach with an ergonomic style of individualized design of personalized information systems provides computer scientists with the opportunity to competently program, organize and support real-time technological processes that are sensitive to the human factor. The direction of development of the programming paradigm reflects a change in the circle of people interested in the development and application of information systems. Many important concepts for programming practice, such as events, exceptions and errors, potential, hierarchy and orthogonality of constructions, extrapolation and program growth points, quality measurement, etc. did not reach a sufficient level of abstraction and formalization. This allows us to predict the development of programming paradigms and select educational material for the future of component programming. If traditional means and methods for selecting reusable components were subject to the criterion of modularity, understood as the optimal choice of minimal coupling with maximum functionality, then the modern element base allows the operation of multi-contact units that perform simple operations. But we can get acquainted with all these types and programming paradigms using even Wikipedia. Currently, there is a very wide range of programming development in different directions.

    Editor's Choice
    , Afghanistan, Tajikistan, Kyrgyzstan, Kazakhstan, Turkmenistan, Russia, Turkey, China, etc. Distribution...

    Georgia is home to hospitable and friendly people who will always help. Having arrived in this sunny country, you don’t have to worry that you will have...

    Rating: / 0 Details Views: 3084 Programming paradigms What is a paradigm in general? You could say that this is...

    Armenian language () is an Indo-European language usually classified as a separate group, less often combined with Greek and Phrygian languages....
    GADES One of the three sons of Cronus, brother of the lord of the sky Zeus and the ruler of the seas Poseidon, also called Pluto (“wealth”, i.e....
    Analysis of craniometric (that is, related to measurements of the skull) indicators of modern humans indicates that all living...
    I was visiting and saw with my own eyes the “world’s first” gypsy alphabet from Ukraine. I thought that the first place on the list of my favorite books...
    Every person has experienced a feeling of guilt at least once in their life. The reason could be a variety of reasons. It all depends specifically on...
    While playing on the bank of the Tunguska River channel, he found a matchbox filled with stearin, inside of which was a piece of paper, darkened...