SteveHopwood wrote:How do you do it? You are able to put your finger on the most inefficient of code and instantly spot the bloop.
I said, "The JSL isn't being updated properly. That's JslPips." So I searched for "JslPips =" and there were only a few choices. Elementary, my dear Watson!
FYI, my limited understanding is that mql4 evaluates all conditionals in an if (a && b && c) even if a fails. Placing these conditionals separately is my own way of trying to cut down on 'overhead'. Limited, I know, but that is me.
That is indeed the way MQL4 works.
However my time and brain cells, and those of the readers of my code, are vastly more valuable than saving a microsecond or three when the code executes. For simple tests like this example, the inefficient MQL4 code is literally just a couple of extra machine instructions. (Assuming they do actually compile it, otherwise it's a few more.) It's an insignificant savings, and it's
really not worth bothering with. It will not make ANY noticeable difference in the execution time -- even if you analyzed it with a code profiler -- yet for this non-benefit you have IMHO sacrificed the readability of your code, and that's always a grave error. Clearly readable and understandable code will pay back FAR more benefits than saving a nanosecond here or there.
Unless there is a very good reason -- like one of the conditions being tested is actually a function call that is expensive or makes an undesirable change -- then I write the code the way I consider clearest for HUMANS to understand. And I find "if (A && B && C)," all in one place visually with the logic spelled out explicitly, much clearer than spreading A, B, and C across extra lines of if's and {}'s, with implied but invisible "and" behavior &etc. If I want to separate them visually I might do something like
Code: Select all
if (Acondition > Avalue
&& !Bcondition
&& (Ccondition > 0 || Dcondition < 0)
...which, to me, is much clearer than
Code: Select all
if (Acondition > Avalue)
{
if (!Bcondition)
{
if (Ccondition > 0 || Dcondition < 0)
{
...
}
}
}
It's in one compact unit instead of being scattered across many lines of code, and I find that easier to see and "grok."
Always do what's best and easiest for you and other readers of your code. You're a much more precious and limited resource than a few CPU instructions.