Declaring variables behind the loop or inside the loop? - page 8

 
Alexey Viktorov:
Not possible, definitely not right. Just one example: In the loop, you look through the open positions. You get a position ticket, you use it to get other properties of the position. There are two variants, either in each function of getting position property insert PositionGetTicket(i) or write it in a variable once and use it. But when the loop is exited this ticket is not needed... Why declare this variable in the body of the OnTick() function or even more interesting at global level?

Perhaps I didn't put it quite right....

Of course they are not needed in OnTick(). I don't know if it's right to put loops (and the variables needed there) into functions?

P.S. In general, any proger should know where a variable is needed and determine its visibility area independently......
 

Generally speaking, string plus and mcl are different. In µl it is the fundamental type, and there is clearly more scope for optimisation. Therefore, it may be wrong to make such an axe-wise comparison. Although I am in favour of uniformity with pluses - it should not be there, so it should not be in µl.

 
Vict:

Generally speaking, string plus and mcl are different. In µl, after all, it's a fundamental type, and there's clearly more room for optimisation. Consequently, it may not be correct to make such a clumsy comparison. Although I am in favour of uniformity with pluses - it should not be there, so it should not be in µl.

Do you speak Belarusian? No? Why? Belarusian language is significantly closer to Old Slavonic. Are we going to speak Russian as opposed to Old Slavonic? Apparently, it is necessary to use Belarusian...

I'm going to get pissed off again... But, once again, the SI and MQL are different languages! Despite the fact that one was based on the other....

 
Сергей Таболин:

Perhaps I didn't put it quite right....

Of course they are not needed in OnTick(). I don't know, maybe it's right to put loops (and the variables needed there) into functions?

P.S. And in general, any proger should know where he needs a variable and determine its visibility area by himself......

Here are the golden words.

And putting a loop in an external function, if it is used only once in code, depends on what religion allows. Many people now stick to OOP and put every little thing into classes or macros. Such a fashion has become popular.

 
Alexey Viktorov:

And putting the loop into an external function, if it is used only once in the code, is a matter of religion.

To add a word to your vocabulary - this religion is called SOLID

 

For those who believe in a clever compiler. Part of the script code is shown below.

The source code is in attached file.

string predictor_names[]={"Time_RSI_ZZ_00","rPeresek_Down","Time_ZZ_02","Speed_1_ZZ_Proc_04"...}

struct sRule
  {
   int               predictor_id;
   bool              more_eq; 
   double            value; 
  };
//Лист дерева(набор правил)
struct sLeaf_r
  {
   int               rules_count;              //Сколько правил
   sRule             rules[32];  //Все правила листа
   double            result_leaf;//Результат листа
  };
//Количество всех листьев 164912
sLeaf_r           leaf_rs[]=
  {
     {3,{{0,0,21.5},{1,1,0.5},{2,0,15.5}},0.0},
     {5,{{0,0,21.5},{1,1,0.5},{2,1,15.5},{3,1,6.5},{4,0,-4.5}},-1.0},
......
......
//Очень много данных
  }

void OnStart()
  {

  }

The structures are completely static, theleaf_rs array can be completely discarded.OnStart() is empty. As a result, the size of the compiled file is almost 2 Mbytes.

Files:
test_3.zip  418 kb
 
Igor Makanu:

To add words to your vocabulary - this religion is called SOLID

Igor, how much older is your father than me? I think not more than 5 years. Is he still able to increase his vocabulary? Or are you too young? Don't look for hidden meanings in my words.
 
Alexey Viktorov:

........

And putting the loop into an external function, if it is used only once in the code, is a matter of religion. Many people nowadays are into OOP and put every little thing into classes or macros. It's a vogue now.

I asked this question once before but never got an answer. Exactly for such cases, in order not to use "their" religion, is there a standard way of destroying a variable?

Still, I personally don't like declaring variables in a loop. I prefer to declare them before it, but how do I destroy them afterwards? ...... That's why the function. After exiting it, the internal variables are destroyed. (???)

I cannot say anything about OOP. I just don't understand why it's needed ))))))) Obsolete, probably ))))))))))

 
Сергей Таболин:

I've asked once before, but haven't heard back. Exactly for such cases, in order not to use "their" religion, is there a standard way to destroy a variable?

I personally don't like declaring variables in a loop, though. I prefer to declare them before it, but how do I destroy them afterwards? ...... That's why the function. After exiting it, the internal variables are destroyed. (???)

I cannot say anything about OOP. I just don't understand why it's needed ))))))) Obsolete, probably ))))))))))

I don't get it, is it?

if (true) {
        Type var;
        for (...) {
                var.use();
        }
}

I doubt they didn't know.

 
Alexey Viktorov:
Igor, is your father not much older than me?

1953-2008 father

1953-2019 father-in-law

This website uses cookies. Learn more about our Cookies Policy.