Can we always avoid the use of the reserved word 'this' in MQL5?

 

I'm taking a look at the MT5 core classes (Array.mqh, List.mqh, Chart.mqh, etc.), and I see that the reserved word this is never used for referring to the object itself inside the class itself.

This is a very common practice in OO languages as far as I know. In fact, MQL5 allows the use of this, but it seems that it is not necessary, so my questions are the following.

Can we avoid the use of this in MQL5? If so, why MQL5 allows its use?

Thank you very much in advance.
Fast Dive into MQL5
Fast Dive into MQL5
  • 2012.08.02
  • MetaQuotes Software Corp.
  • www.mql5.com
You have decided to study MQL5 trading strategies' programming language, but you know nothing about it? We have tried to examine MQL5 and MetaTrader 5 terminal from the newcomers' point of view and have written this short introductory article. In this article, you can find a brief idea of the possibilities of the language, as well as some tips on working with MetaEditor 5 and the terminal.
 
laplacianlab:

I'm taking a look at the MT5 core classes (Array.mqh, List.mqh, Chart.mqh, etc.), and I see that the reserved word this is never used for referring to the object itself inside the class itself.

This is a very common practice in OO languages as far as I know. In fact, MQL5 allows the use of this, but it seems that it is not necessary, so my questions are the following.

Can we avoid the use of this in MQL5? If so, why MQL5 allows its use?

Thank you very much in advance.

This is well explained in the documentation. To resume :

  • this keyword isn't mandatory to access members of a class.
  • It's a good practice to use it anyway (my opinion).
  • If you want to return a reference to an object from a function (method), you have to use it.
 
angevoyageur:

This is well explained in the documentation. To resume :

  • this keyword isn't mandatory to access members of a class.
  • It's a good practice to use it anyway (my opinion).
  • If you want to return a reference to an object from a function (method), you have to use it.

Thank you again angevoyageur!

Official Docs only use this for returning the object itself, not for referencing class members. The MQL5 framework does not use this! so I will do the same, I mean Unlike C ++ and Java I am writing the reserved word this only when strictly necessary. I expect everything works!

Reason: