Talking about the PLO in the lounge - page 6

 
George Merts:

This (and all beginning with underscore) is a protected function of the class.

Well, they are merged into one!

There is only one function - Compare(), but we have to perform a comparison by the key being passed. Correspondingly, one of the particular protec-ted functions is chosen. That's why they are protected (protected), so that the user cannot access them - they are called only from Compare() and this is indicated by underlining.

This is also one of the code design rules - a function starting with an underscore is not intended to be called by users, it serves only certain in-class tasks. Access to it is restricted.

But why such circus tricks when it's much easier to do everything with classics. Use wrapper functions and curly braces to hide nested variables and functions and prevent access to them and you'll be happy. You'll only confuse yourself and others with these protectoids...

 
Andrei:

But why such circus tricks when everything is much easier to do via classics. Use wrapper functions and curly braces to hide nested variables and functions and prevent access to them and you'll be happy. You'll only confuse yourself and others with these protectoids...

I don't get it... Protected is an access modifier for a function. That is, a protector function is used, which can only be accessed from a function of a class or its descendant. Plus the underscore means for me personally that there are some implicit assumptions which must be taken into account when using it.

Dennis Kirichenko correctly noted - you could write everything in one Compare() function. But then it would be two dozen screens, it would be unrealistic to look through it and harder to modify than now.

I've left only key selector in Compare() function, while the code which makes comparison for particular keys is placed in separate functions. Since these functions are highly context-specific, they are declared in the protected section of the class, so that they could be accessed exclusively from another function of the class or descendant. And to also remind myself that these functions are intended to perform a specific narrow task within another function - I start them with an underline. If I come across such a function in the future - I will immediately see that there are implicit assumptions that need to be taken into account when calling it.

It seems that you (let's refer to "you") don't quite know what access modifiers are and why they are needed.

 
George Merts:

I don't get it... Protected is an access modifier for a function. That is, a protector function is used, which can only be accessed from a function of a class or its descendant. Plus the underscore symbol to me personally means that there are some implicit assumptions to consider when using it.

Well, you can restrict access to a function in classic ways, without any OOP.
 
Artyom Trishkin:

But no personal insults...

Please clean the thread from flooding, leave onlyAlexey Volchanskiy's educational posts
 
Andrei:
Well, you can limit the access to the function by classical means, without any OOP.

How ?

Here is the task - to make it so that in future, when modifying the code, it would be impossible to take and use a certain function "anywhere". How to do it without OOP-restriction ofaccess to the class space with the help of public-protected-private modifiers?

 

Apparently static and const (this is not OOP) are not needed.

As for OOP, very interesting, how would the following function, which has wide practical application (not abstract at all), look like in procedural style?

Forum on trading, automated trading systems and strategy testing

Organizing an order overflow cycle

fxsaber, 2017.10.18 12:29

Version without reference to history.
struct HISTORY_UNIT
{
  long Ticket;
  int Type;
  double Lots; 
    
  HISTORY_UNIT( void ) : Ticket(::OrderTicket()), Type(::OrderType()), Lots(::OrderLots())
  {
  }

  bool operator !=( const HISTORY_UNIT &Unit ) const
  {
    return((this.Ticket != Unit.Ticket) || (this.Type != Unit.Type) || (this.Lots != Unit.Lots));
  }
      
  bool IsChange( void )
  {
    const HISTORY_UNIT Tmp;
    const bool Res = (this != Tmp);
    
    if (Res)
      this = Tmp;
      
    return(Res);
  }
};

// Возвращает true только в случае, если с последнего вызова произошли торговые изменения
bool IsChange( void )
{
  static HISTORY_UNIT History[];  

  const int Total = OrdersTotal();  
  bool Res = (ArraySize(History) != Total);

  for (int i = 0, j = Res ? ArrayResize(History, 0, Total) : 0; i < Total; i++)      
    if (OrderSelect(i, SELECT_BY_POS))
    {
      if (Res || (Res = History[j].IsChange()))
        ArrayResize(History, j + 1, Total);
      
      j++;
    }
  
  return(Res);
}

This version is especially relevant for MT5 on VPS, as MT5 works with History very slowly and is computationally expensive.

Obviously any OOP can be rewritten in procedural style. But it's the practice that interests me. So I took the above tiny code where OOP is used to a minimum as well.

So how much nicer/more convenient/more readable/more correct is procedural style compared to OOP in this example? Well, not to talk for a few pages, but just to compare short source code procedural vs OOP. I ask OOP opponents to show a master class. This is not the dreaded MT5, but the good old MT4.

 
Vladimir Pastushak:
Please clean this thread from flooding, leave onlyAlexey Volchanskiy's educational posts

It's late )))) especially as I will only be able to find time this weekend, it suddenly turned out to be very busy

Will do some studies this weekend, maybe some videos too.

 
Vladimir Pastushak:
Please clean the thread from flooding, leave onlyAlexey Volchanskiy's educational posts

Vladimir, if you haven't learned for all these years, it's too late to start;).

 
fxsaber:

Apparently static and const (this is not OOP) are not needed.

As for OOP, it is very interesting how the following, which has wide practical application (not abstract at all), function would look like in procedural style?

Obviously, any OOP can be rewritten in procedural style. But I'm interested in practice. So I took the above tiny code, where OOP is also used to a minimum.

So how much nicer/more convenient/more readable/more correct is procedural style compared to OOP in this example? Well, not to talk for a few pages, but just to compare short source code procedural vs OOP. I ask OOP opponents to show a masterclass. This is not the dreaded MT5, but the good old MT4.

You're getting too convoluted even in this simple example. It's always easier to re-write OOP than to understand someone else's code.... What do you want to do, at least tell me in plain human language? Find out what is the change in the order history?
 
Vasiliy Sokolov:

Vladimir, if over all these years they still haven't learned, I think it's too late to start;)


Can I ask who they are and what they have not learned? Moderators have not learned to clean or something else ).

ZS: By the way, in the whole thread did not see a single wish to cover any topic, as always, the usual rancor. So I decided to record videos on YouTube from scratch on how OOP works, at least it will be of some use. Anyway, in a while the branch will end up in the branch_sucker.