OOP vs procedural programming - page 9

 
Реter Konow:
I understand why I don't understand it, it's not my code, besides it's only a part of it. But you don't seem to understand it either - or am I wrong?

I don't use pointers...

Earlier I worked in the same way as you, only with functions, but with time they had to be stored somehow, then I had to search for them, each function did its own extra actions.

Now I've rebuilt everything into classes and when I call Order class I get everything I need and a list of available functions and methods...

 
Реter Konow:
That's why I like to make big generic blocks of code.

Can't even believe the author of a good GUI without OOP

Saving lines of code?!

 
СанСаныч Фоменко:

No, your example is very good.

It's not about procedural programming.

There is a much more important criterion of program quality: code clarity.

The solution you've given is awful: it is not at all clear WHAT function is being called in a meaningful way. I would write a normal switch and a comment against each call. This is the right code.

I conclude from your example that OOP is a harmful thing.


And why switch for 100 variants if you know in advance that only 1 will be used?

What's the sense of a sprawl of 100 variants of switch compared to three lines of code?

It is not right to make complex, large and slow-moving what can be done rationally, optimally (even perfectly).

OOP is harmful only if you use it incorrectly.

Please respond to this comment.

 
Реter Konow:
That's why I like to make large, universal blocks of code.

What makes them universal?

 
Dmitry Fedoseev:

Why do you need a 100-variant switch when you know in advance that only 1 will be used?

What is the clarity of a 100-variant switch compared to three lines of code?

Making complex, large and slow things which can be done rationally, optimally (even perfectly) is not the right approach.

Please respond to this comment.


It's not a spoiler - it's a documentation of the program's functionality combined with the program's text. This is the most important thing, not what will work alone

 
Vladimir Pastushak:

I don't use pointers...

Earlier I worked in the same way as you, only with functions, but with time they had to be stored somehow, then I had to search for them, each function did its own extra actions.

Now I rebuilt everything into classes and when I call Order class I get everything I need and a list of available functions and methods...

If it's more convenient for you, I have nothing against it. From my rather rich experience in programming, I can say that any tasks can be solved without OOP just as effectively, if you apply universalization and compression to your solutions. This is an experience which is confirmed by great practice. Perhaps one or another approach is related to individual peculiarities of our thinking. This is the main point I would like to convey.
 
СанСаныч Фоменко:

This is not a spoiler - it is documentation of the programme's functionality combined with the programme's text. This is the most important thing, not what will work alone


Both the slop and the ballast. The flies should be separate, the cutlets separate. Documentation is important, but it should not interfere with the operation of the program.

 
Dmitry Fedoseev:

What makes them universal?

For example, you need a block that positions graphical objects relative to each other by creating controls. At the same time, the same block controls the phenomenon of objects, i.e. it hides some objects and reveals others. It also calculates scrollbar dimensions and overall window dimensions. It also calculates the slider movement in the scroll bar. This is the universal block of object relationships.


Or a block that controls the size of the window when the window handle is gripped. Or a block that controls the states of controls. Or the block which calculates which element the cursor is on and simultaneously brings many global parameters into focus...

 
Реter Konow:
For example, you need a block that positions graphical objects relative to each other by creating controls. At the same time, the same block controls the phenomenon of objects, i.e. it hides some objects and reveals others. It also calculates scrollbar dimensions and overall window dimensions. It also calculates the slider movement in the scroll bar. This is the universal object relationship block.

But this is implemented through if and switch, isn't it?

 
Dmitry Fedoseev:

But this is implemented through if and switch, isn't it?

Yes, these blocks have both. But trust me - they are compressed to the max and versatile, because they solve a wide range of problems.
Reason: