OOP, templates and macros in mql5, subtleties and uses - page 6

 
Alexey Viktorov:

Here we go.

So all your codes are made on crutches? It's nothing personal.
Yes, approximately so. For MQL has no full-fledged OOP. Plus there are a lot of bugs, which I regularly report, but without success. And I have to defend myself against bugs with crutches, what can I do.
 

Here's how we do it.

If static variable is initialized with constant, this initialization will be done at global initialization step, as before
Otherwise (call or variable initialization), static variable will be initialized at first call (it will be like in C++), this call itself will be wrapped in a condition with implicit global variable/flag, for example

for MQL code:

class CFoo { };

void func(bool f)
  {
   if(f)
     {
      static CFoo foo;
      foo.MakeMeHappy();
     }
  }

The following pseudocode will be generated

CFoo static_func_foo={}; // zeromem only
bool static_func_foo_init=false;

void func(bool f)
  {
   if(f)
     {
      if(!static_func_foo_init)
        {
         static_func_foo.CFoo();  // constructor call
         static_func_foo_init=true;
        }

      static_func_foo.MakeMeHappy();
     }
  }
 
Alexey Navoykov:

You still have to separate them somehow in the function.

Not necessarily and not always. I won't give you examples, so as not to litter the thread.

 
Ilyas:

Here's what we're going to do.

Great news! The gods have heard our prayers after all.)
 
Alexey Navoykov:
Yes, approximately so. For MQL has no full-fledged OOP. Plus there are a lot of bugs, which I regularly report, but without success. And against the bugs I have to defend myself with crutches, what can I do.

You've got me all confused. If in ... read your words

Forum on trading, automated trading systems & strategy testing

Peculiarities of mql5, tips and tricks

Alexey Navoykov, 2019.01.25 11:44

If the parameters are of different types, it is reasonable to make several overloaded methods with the corresponding types. You have to share them in functions anyway, so it's better to divide them into separate functions, than to make a mess, which in addition takes anonymous type, ie you can mistakenly pass anything into it and get a compilation error inside the library, that is not good. Or may not even get, which is doubly bad.)

In short, in full-fledged OOP template functions are a crutch (with few exceptions).

And there's no full-fledged OOP in MQL... Even crutches are missing? I don't understand anything at all.
 
MQL is all good with OOP, and if multiple inheritance is added (at least for interfaces, because they are useless in their current form), it will be perfect.
 
Ilya Malev:
MQL is OK with OOP, if they add multiple inheritance(at least for interfaces, because they are useless in their current form), it will be perfect.

So, interfaces are the basis of normal OOP, and you're saying that everything is fine in MQL.

 
Alexey Navoykov:

So interfaces are the basis of normal OOP, and yet you say that everything is fine in MQL.

The basis of normal OOP is polymorphism, not interfaces. Interfaces are the basis of a certain class structure. In general, I would love to talk about these topics, but I'm afraid this thread is not the place for it.

 
Ilya Malev:

The basis of normal OOP is polymorphism, not interfaces. Interfaces are the basis of a certain class structure. In general, I would be glad to discuss these topics, but I'm afraid this branch is not suitable for it.

We are discussing particularities of the MQL language and the absence of multiple inheritance is quite a characteristic feature).

Ok, the basis of course is polymorphism, but without separate interfaces it is not convenient in use. This often leads to passing objects as template arguments instead of interfaces.

I've described here my variant of simulating multiple interfaces. Accordingly, a class can be declared like this:

class A : public Interface1<Interface2<Interface3<CBase>>>
{
 ...
};
 
Alexey Navoykov:

We are discussing peculiarities of MQL language and the absence of multiple inheritance is quite a peculiarity).

Ok, the basis of course is polymorphism, but without separate interfaces it's not convenient in use. This often leads to passing objects as template arguments instead of interfaces.

I've described my variant of imitating multiple interfaces here. Accordingly, a class can be declared as such:

In my opinion, it's not all bad. There are not so many basic main interfaces in C# that their methods could not be reduced to one basic superclass and then inherited.

P.S. To implement something multiple through constructions like <<<<>>>> is a bit of a pain in the ass. It is better to do functions through operators, e.g. a==b calls a.compareto( b ), a[comparer]==b calls comparer.compare(a,b), etc.
Reason: