Self-learning the MQL5 language from scratch - page 45

 
Vladimir Simakov:

There's a good anecdote about this:

- Question: what is the best type for a global variable in c++?

- Answer: //.

Good anecdote. Thank you!

Regards, Vladimir.

 
Реter Konow:
This is certainly informative, but global variables should be initialized explicitly for clarity. For example, in mql4 variables/arrays can not be initialized anywhere at all when being declared, and they still get initial zero. ))
#property strict

int Test(){
   int a[10];
   int ret=0;
   for (int i=0;i<10;ret+=a[i++]);
   return ret;
}

void OnStart(){
   Print(Test());
  }
 
Vladimir Simakov:
And... what is it?) Prints out the sum of the addition
of cell values of an explicitly uninitialised array. Where? Mql4? Mql5? How does it relate to the fact that it's desirable to initialize global variables for clarity? Does it confirm, refute the thesis?))
 
Реter Konow:
And... what's that?) You print out the sum of the addition
of cell values of an explicitly uninitialised array. Where? Mql4? Mql5? How does it relate to the fact that it's desirable to initialize global variables for clarity? Does it confirm, refute the thesis?)))

I highlighted there in colour)

Or are you still in the era before

#property strict
living?
 
Peter, let's have a challenge. You come up with an example where globals are really needed, and I'll rewrite it without using globals.
 
Vasiliy Sokolov:
Petr, let's have a challenge. You come up with an example where globals are badly needed, and I'll rewrite it without using globals.
My visa editor. ))))

Just kidding. All right, Vassili, I'll think about it.
 
Vladimir Simakov:

I highlighted it there).

Or are you still in the era before

era?
It's spelled both ways. Checked it. There's no error...
 
Vasiliy Sokolov:
Peter, let's have a challenge. You come up with an example where globals are really needed, and I'll rewrite it without using globals.
But tell me, why are you against them? I just can't figure it out. Refuse to globaloks, like shooting yourself in the foot. They're so handy, aren't they?
 
Реter Konow:
But tell me, why are you against them? I just can't understand it. Rejecting the globals is like shooting yourself in the foot. They're so convenient, aren't they?
Peter, on the contrary!
 
Vasiliy Sokolov:
Peter, on the contrary!
When programming procedurally, is it possible to do without globally declared variables? I'm technically not sure how to write EA functionality without OOP and not using global variables.

Functions must have a shared memory.
Reason: