I want to what is good practice to write code in these 2 styles with considering "program performance" only so program runs fast and smooth consuming less memory.
In terms of memory consumption the difference between the two examples is minimal. Both examples involve the same amount of variables (open and close in the first example, and no additional variables in the second example). The main difference lies in how the code is structured and the amount of lines used. The second example is more elegant and minimalistic (these are the 2 aspects that a good coder should always be looking for).
From the point of view of memory consumption the declaration of local variables in the first example may take a little more space because of the additional variables, but I insist, in this particular case in terms of efficiency the difference is negligible.
That is my opinion. 😅
In terms of memory consumption the difference between the two examples is minimal. Both examples involve the same amount of variables (open and close in the first example, and no additional variables in the second example). The main difference lies in how the code is structured and the amount of lines used. The second example is more elegant and minimalistic (these are the 2 aspects that a good coder should always be looking for).
From the point of view of memory consumption the declaration of local variables in the first example may take a little more space because of the additional variables, but I insist, in this particular case in terms of efficiency the difference is negligible.
That is my opinion. 😅
//code 1 string sym = _Symbol; ENUM_TIMEFRAMES tf = PERIOD_M1; int bar = 10; double open = iOpen(sym,tf, bar); double close = iClose(sym,tf, bar); double high = iHigh(sym,tf, bar); double low = iLow(sym,tf, bar); void Function1() { if(open>close) // do something } void Function2() { if(open>close) // do something } ..... void Function100() { if(open>close) // do something }
//code 2 void Function1() { if(iOpen(_Symbol, PERIOD_M1, 10)>iClose(_Symbol, PERIOD_M1, 10)){ // do something } } void Function2(){ if(iOpen(_Symbol, PERIOD_M1, 10)>iClose(_Symbol, PERIOD_M1, 10)){ // do something } } ..... void Function100(){ if(iOpen(_Symbol, PERIOD_M1, 10)>iClose(_Symbol, PERIOD_M1, 10)){ // do something } }
my use case if i have hundreds of functions which are called on a program, So as per your feedback I believe minimalistic code (code2 ) is much better for performance rather than declaring variables? and should this practice be approached by a good programmer?
More things should be taken into account, such as how many times it will be called (if on each tick, etc), or even if open and close are worth declaring them as in example 1 because they are needed for something later on. My opinion is based on those examples being all the code, but logically it won't be like that, so you should evaluate whether to do it one way or there is a plausible explanation to do it another way.
More things should be taken into account, such as how many times it will be called (if on eac
My all 100+ functions are only called once at Onchartevent on press of key event but sometime they do not load all at once, in multiple press of keys it loads that is why I am asking this for performance
I still think there won't be much of a difference. Nowadays, any computer can handle that (both example 1 and 2) in a matter of milliseconds. If it were complex calculations, I would understand your concern for efficiency, but although it's always good to care about that and, as I mentioned before, be elegant and minimalist, in this particular case, it really doesn't matter how you do it.
However, to the question of which is more efficient without having all the code in front of me and knowing exactly everything it does, the answer is simple; the second example wins.
I still think there won't be much of a difference. Nowadays, any computer can handle that (both example 1 and 2) in a matter of milliseconds. If it were complex calculations, I would understand your concern for efficiency, but although it's always good to care about that and, as I mentioned before, be elegant and minimalist, in this particular case, it really doesn't matter how you do it.
However, to the question of which is more efficient without having all the code in front of me and knowing exactly everything it does, the answer is simple; the second example wins.
Thank you.
I still think there won't be much of a difference. Nowadays, any computer can handle that (both example 1 and 2) in a matter of milliseconds. If it were complex calculations, I would understand your concern for efficiency, but although it's always good to care about that and, as I mentioned before, be elegant and minimalist, in this particular case, it really doesn't matter how you do it.
However, to the question of which is more efficient without having all the code in front of me and knowing exactly everything it does, the answer is simple; the second example wins.
Relax...
The OP is not asking about what is faster; they are asking about what consumes more memory. Therefore, storing results is ruled out.
Here, the focus is on the OP, not engaging in absurd battles over why you said this or that. You gave your opinion, and I gave mine.
End of story.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to what is good practice to write code in these 2 styles with considering "program performance" only so program runs fast and smooth consuming less memory.