A question for OOP experts. - page 16

 
Georgiy Merts:

That's right, more about this function. You have one monstrously sized switch that selects one of a dozen functions you need. In such a switch, it's very easy to make a mistake by accidentally writing code relating to one of the branches in the wrong place.

Things are much simpler with an overload. We have ten different descendants, and each time we work with ONE class, and it has ONE overloadable function. We cannot accidentally write it in another class, because we have to open a completely different file for it.

Plus - the parsing itself in this very huge switch is, in my opinion, much more stressful than opening the one class we need, and then parsing just one function.

In fact, in assembler code all this switch's handling anyway comes down to the same swich, depending on this pointer. But in case of OOP all this is hidden from the programmer and doesn't interfere with his work. Without OOP - you have to deal with it.

Roughly speaking, when you walk - you end up sending signals to your muscles in a certain sequence that move them. However, on the level of consciousness - you just remember which movement to make. Here, OOP is exactly that kind of "memory of what movement to make". You "don't understand why we need to remember the movement when we have a bunch of muscles, and nerves wired to them". well... I've said many times before, for titans of memorisation, it's really quite enough to remember which muscles have to be tensed in what sequence to go. There's no point in remembering the whole movement. For others, who cannot remember so much, it is much more reasonable to remember the whole movement, and what is there with the muscles, in what sequence they are tensed and to what extent - it is more reasonable to hide it from the mind.

Yes, George, your arguments are reasonable and logical. Indeed, my approach requires you to remember and know everything in your program. This is both good and bad. Good, because knowing ensures quick development of code and solutions, little syntax and a lot of functionality, and bad, because there is no provision for portability of parts of code to other programs due to global interconnection of all blocks.

Our spoken language, after all, also uses global memory. We know and remember all the words and not only those belonging to the current topic of conversation. Everything is jumbled up in our minds. That's how Mind works, and that's how my approach works. All the most important results of the functional blocks are universally available. And so, within them is almost human terminology. I speak in code, like a normal language. It's very convenient. But, there is a lot to remember. It's true.


ZS. By the way, the giant switch can be broken down into files and the contents hidden. It's just convenient for me to see the whole thing.

 
Vict:

Tinny, you're doing some kind of bike building without a proper study of the conventional approach. Peter, find a good book, perhaps Stroustrup, in some book he wrote a text editor, you will learn something from a real problem, I don't remember the content, but it is unlikely to teach you bad things.

Thank you, of course. But it is unlikely that specific tasks can open my eyes to something, because I have solved myriad of them over the last 6 years. A real myriad. So I know what I'm talking about.
 
Now to efficiency. Switch is ultimately what? It is a sequential comparison of a parameter with constants. Attention Peter, sequential. That is, if the sought constant is 100500, then all these comparisons on the processor will be done. What are overloaded functions/methods - these are completely different code blocks in machine code after compilation, with their own entry points. So which is more efficient?
 
Реter Konow:
Thanks, of course. But specific tasks are unlikely to open my eyes to anything, as I've solved a myriad of them in the last 6 years. A real myriad. So I know what I'm talking about.

There are a lot of tasks, and you still haven't understood the usefulness of overloading. Imagine that a template function, its arguments may pass through int, double or user type, and we want to find an absolute value through abs(), how can we do it without overloading?

I'd like to see your crutches around these arrays when the project grows: simulate a car wheel -> car with 4 buggies -> road with a hundred cars.

 
Vladimir Simakov:
And now to efficiency. Switch is what in the end? It is a sequential comparison of a parameter with the constants. Attention Peter, sequential.

No, switch works differently. It is a table in which the switch goes directly to the desired constant. This is a significant difference from the if block.

 
Vladimir Simakov:
And now to efficiency. Switch is what in the end? It's a sequential comparison of a parameter to constants. Attention Peter, sequential. That is, if the sought constant is 100500, then all these comparisons on the processor will be done. What are overloaded functions/methods - these are completely different code blocks in machine code after compilation, with their own entry points. So which is more efficient?

Alas, the inevitable overkill. In this I lose, in the other I win.

For example, the function with the giant switch performs positioning of objects in items and items in windows. It calculates their sizes. I call it once and all elements and all objects are placed at their positions according to their anchor points. Calculates their sizes and position relative to each other. Determines which elements should be hidden, what is the required kanvas size and so on... One call is a huge job. The same block can calculate size or position of one window element out of thousands. One block. The call is Object();

How many classes and functions would I have to write in OOP to solve such a number of tasks? I'm afraid to imagine.

 
Реter Konow:

Alas, the inevitable overkill. In this I lose, in the other I win.

For example: The same function with a giant switch performs positioning of objects in elements and elements in windows. I call it once and all elements and all objects are placed at their positions according to their bindings. Their sizes and positions are calculated. It is determined which elements should be hidden, what is the required kanvas size and so on... One call is a huge job. The same block can calculate sizes or positions of one window element out of thousands. One block.

How many classes and functions would I have to write in OOP to solve such a number of tasks? I'm afraid to imagine.

About 5-10, at a rough guess. With a completely self-explanatory interface.
 
I mean the number of classes. Each one is 200 lines long.
 
Ihor Herasko:

No, switch works differently. It is a table in which the switch goes directly to the desired constant. This is a significant difference from the if block.

So, in terms of speed, this is obviously the fastest option in MQL. But the access tothe class objects in the managed environment is indirect.
 
Реter Konow:

We make a function without parameters, write all overloaded function calculations inside, make variables global and have access to results from any other function. Well, it's a beauty, isn't it?

Yeah, it's just fine... We should put it in the "Humour" branch. )