A
A
alex4answ2020-03-06 08:05:01
Programming
alex4answ, 2020-03-06 08:05:01

What is the essence of procedural programming?

Good afternoon, for 3 years I have been writing only in the OOP style, very rarely

I have to write something in the procedural style, something small and fast

from OOP in favor of another?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
V
Victor Bomberow, 2020-03-06
@alex4answ

alex4answ , the procedural style uses only the concepts of memory model, types, instructions, program and subroutine.
That's all. No composite types. The concept of "state" is not expressed in any way in the code. Keep it in your head or in the comments if you want.
No entities in code. Keep them in your head or in the comments.
There is no concept of a function. A function is too complicated in terms of procedural programming. These are some special requirements for the subroutine, the more it is required to introduce the concept of arguments and function parameters, which requires some kind of complex memory model with the concepts of static , constant , pass by value, pass by reference, etc.
But all this is already being introduced in structured programming.
Procedural programming introduces a memory model with the concepts of stack and heap. If you want to make a function in a procedural paradigm, you will have to arrange it as a subroutine and call it from another. Moreover, there is no concept of linking, you will do this using the address in the heap, and some data, such as arguments, will be placed on the stack yourself, each time you call the "function" subroutine.
Oh yes, if you want a function for adding two numbers, you will have to do ctrl-c, ctrl-v and in the body of the subroutine write the addition of two pieces of data taken from the stack. For the difference - copy the code, change the instructions in the body. And so for each function.
Yes, there is no concept of scope, you will have to express it in the code in this way yourself.
Well, since the OS will not let you climb beyond the limits of one process, the subroutine will have to be put in sorts higher than your code.
And the maximum abstraction that procedural programming introduces is symbolic arbitrary naming of an address in memory. And instead of types, rather, a byte offset is used for the collection, which are simply given names.
The fact is that one can speak of the procedural paradigm only in retrospect. Basically, the procedural paradigm is classical assembler.
An IDE can help solve many issues as a static analysis, but it's easier to make a smart compiler once and switch to a language that allows you to abstract. At first, it was not entirely clear what set of goodies should be sewn into the compiler. But over time, people gave birth to the C language.
Retrospectively, for the procedural paradigm, the following scope can be defined: any mathematical problems.
Those. you take a modern compiler / interpreter of any language, write a solution in one file, do not use composite types, but only integrated simple ones (if you have chosen a language with strong typing), do not use functions, but only operators, when you finish, look at the code - you solved the problem within the framework of the procedural paradigm.
There are, of course, but - modern languages, except for assembly, do not have full support for the procedural paradigm. Moreover, many languages ​​don't even have support for the structural paradigm unless the language can use strong typing.
But in a language with full support for the procedural paradigm, you can make such subroutines that cosplay functions, but return several "arguments", and write directly to memory. And in principle, in the procedural paradigm, you can make your own ABI, there are no standards, there are no rules, nothing is true and everything is allowed.

R
res2001, 2020-03-06
@res2001

You can easily write in the OOP style in a procedural language. Of course, there are no buns in the form of ready-made structures, and there will be more code than the same one implemented in OOP. But this does not mean that the code will be slower or less efficient, it's just that in OOP the programming language (compiler) does some work for you, and in procedural you do it yourself and this fact increases the size of your code.
In general, OOP grew out of a procedural style.
By saying that many projects are written in a procedural style, you're overstating the importance of "style". In fact, many projects are written in C (the procedural style is simply applied there as a given) and there are a lot of reasons for that.

F
felony13twelve, 2020-03-06
@felony13twelve

Writing normal code is not using OOP, this is complex code, OOP it is more simplified

K
Kosika, 2020-09-12
@Kosika

Procedural programming can be easier than OOP when solving simple problems.
Some languages ​​allow programming in both procedural and OO programming paradigms. For example, the PHP language.
Here are examples of PHP codes that output "Hello, world!", written in procedural and OO approaches:

  • procedural approach:

<?php
print "Hello, world!";
?>
  • OO approach:

<?php
class helloWorld {
function myPrint() {
print "Hello, world!";
}
}
$myHelloWorld = new helloWorld();
$myHelloWorld->myPrint();
?>
As you can see, it is easier to use procedural programming to solve simple problems.

S
Stavr Strelov, 2020-03-06
@IAmNoob

This is when you just write commands - procedures. Without classes, methods, all in one file and in the form of commands)

J
juchkovdavid, 2022-03-30
@juchkovdavid

All code is written in a procedural style.
The structure is as follows:
js/main.js - processing of forms, buttons, asynchronous output of html to the page (received by requests to the procedural code).
post - directory, contains *.php files, requests from forms, buttons, content request are sent to them.
Note: I no longer use jquery and other libraries, because enough developments on pure js :)
Am I the only one here?
ps: I also work on CMS, but the structure depends on CMS. OOP is rare for me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question