O
O
Outoverlay2015-12-30 00:59:02
PHP
Outoverlay, 2015-12-30 00:59:02

When is oop faster than procedural?

When is oop faster than procedural?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
M
Mercury13, 2015-12-30
@Outoverlay

OOP is not designed for execution speed, but for the speed of developing . As, however, and many other modern development technologies. Everything that OOP does can be done without OOP, and even more efficiently. Whether it's worth it is another question.
What problem does OOP specifically solve? Curb the complexity of developing programs built from cooperating components. This is why we dance: if the program is not modular (for example, some kind of complex scientific calculation), OOP will not help much. Also, OOP will not help if the standard implementation of OOP is not sufficiently efficient in terms of processor or memory - for example, when I was a JavaMe, OOP was not favored, because it ate a lot of memory, a typical mobile phone had from 215 to 800 kilosbytes of available memory. It will also work badly where there is no interaction (on typical PHP, which gave out a page and disappeared).
What can be implemented object-wise in PHP?
• Support for some protocols (database, mail, some external web service like VK API or Mandrill).
• Something from the subject area that changes its state - for example, generating images, sounds, archives, PDF ...
• Maybe you can make some kind of page generator that first assembles the page skeleton, and then, depending on the settings and the target device , turns it into HTML code.

A
abcyu, 2015-12-30
@abcyu

When the code is huge and you fornicate in it and do jambs.

O
OnYourLips, 2015-12-30
@OnYourLips

Always.
After a certain amount of code, procedural is difficult to understand, as a result, you lose a picture of how the application is organized and built.
You get a lot of bugs, duplicate code appears, and working time is spent on fixes, and not on new functionality support and optimization (optimization is an architectural issue).
As a result, the code will run slower than its well-maintained OOP counterpart.

D
Dmitry, 2015-12-30
@EvilsInterrupt

Everything depends on you, i.e. from your way of thinking. your abilities.
Perhaps it will be easier for you to go to your head with "functionality" than OOP, and this is not scary and not bad. It's just your personality.
But practice shows that for many people it is much more familiar and easier to think if they write OOP-nuto code. And indeed. We humans already think in objects. For us, the wing did not take parameters and waved itself, but simply "Birds fly"! We see cashiers, birds, dogs, bosses, and other entities. We divide them by occupation: accountants, programmers, dentists, etc. We divide them by social. sign: pensioners, students, etc. We already think in terms of types, objects, characteristics and actions that they can perform. Usually, it doesn't occur to people that "Birds crawl and crawl into holes", because in our head there is a "bird" interface in which "flies, has wings" is wired.
Look around. We already think in objects, so it's easier for most programmers to write in OOP style.

M
Mrrl, 2015-12-30
@Mrl

I don't know about PHP, but I'll use C/C++ as an example.
If virtual functions are not used, then C and C++ will give the same efficiency.
If you try to write the same code that requires run-time polymorphism in C and C++, then, most likely, C++ code will be more efficient. Because you don't have the patience to accurately fill in and use virtual function tables, and you end up with code with a lot of case, and even if / else on object tags. Ultimately, it will be possible to write a C program equivalent to a C++ program (and then optimize it), but it will be complex, incomprehensible, and practically not extensible: adding a new polymorphic method to the type system (with modification of all tables and all methods working with tags) will be a pain.

V
Vlad Tokarev, 2015-12-30
@Vadiok

If you do not consider the speed of development, then the only option that comes to mind is autoloading classes in PHP. If we compare 2 such options - classes are loaded if necessary through __autoload (), and functions are loaded all at once, then the performance is higher for classes, because extra code is not loaded.

V
Vitaly, 2015-12-30
@vt4a2h

In general, the question is rather strange. I don’t know how things are with PHP, but about C ++ I would say: grab the profiler, release build and see. And then, how much faster, is performance critical, what is the priority - performance or support and extensibility ...? Usually, the entire code does not require optimization in terms of speed, only some places (which sometimes you can rewrite at least in assembler, but due to the peculiarity of the algorithms, you will not get more speed).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question