Features of the mql4 language, subtleties and techniques - page 11

 
Ihor Herasko:

In many software companies, code like this would get all their fingers beaten off. The first thing that is always and everywhere required is to avoid "unnecessary reading". For example, if a condition is used when entering a function:

then it is recommended to write:

This approach helps a lot when there are no conditions attached.

Once again, it will be a pain in the neck. After all, nobody checked what the OrderType() function returned. Or maybe it returned -1 or 6? This is an example of laying into the compiler's properties which you should always stay away from. You yourself cite many examples of cross-platform code. So why are you moving away from it in this case? A new MQ compiler will come out and this code will no longer work correctly.

What do software companies have to do with what we're discussing! The code won't stop working, no need for cospirology here.

It's the same situation with continue. Code like:

is harder to read than:

And yet the efficiency of execution is the same in both cases.

In this case, code of one line is easier to read than code of six lines. Moreover, it is more logical because it is not bound to be inside a loop in any way. I.e. you can copy-and-paste the first case without worrying about the second one.

 
fxsaber:

The Lots[] example above is a treasure trove of how code can be both super-laconic and totally understandable.

It's you who finds the code understandable. But someone who only looks through the documentation and sees your code will wonder why the array's size is 8, while the documentation contains only 6 order types.

And personally, I also find it easier to read conditions if they are separated separately, i.e. like this:

if (!OrderSelect(i, SELECT_BY_POS))
   continue;

if (OrderSymbol() != Symbol())
   continue;

if (OrderMagicNumber() != m_nMagicNumber)
   continue;

I'm also more comfortable than like this:

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == m_nMagicNumber)
{
}

But I think it's a matter of taste and habit. No one needs to impose or prove anything.

On the other hand, I agree with you that:

MT4-история торгов отсортирована по времени закрытия и это правило меняться не будет.

And I think it's logical, and I don't remember any other times.

 
Alexey Kozitsyn:

For you the code is understandable. But someone who has just looked through the documentation and seen your code will immediately wonder why the array has size 8, while the order types in the documentation are only 6.

So you see how a simple code generates right questions in people's minds! And after that, should you trust everything written in the Documentation?

 
fxsaber:

And after that, should you trust everything in the Documentation?

you should, it is a basic principle ofRTFM programming

RTFM
  • lurkmore.to
RTFM (изначально сокр. от англ. read the following manual, «обратитесь к прилагаемому руководству») — типичный ответ службы поддержки на вопрос пользователя, обычно сопровождающийся номером или названием этого руководства.
 
Igor Makanu:

should, it is a basic principle ofRTFM programming

Realities contradict this principle.

 
fxsaber:

What do software companies have to do with what we're discussing!

Well, who else can you cite as an authority?

The code won't stop working, no need for cospirology here.

Yes, in MT4 with 99% probability it is, because MT4 is almost buried. But try to pull such a stunt cross-platform and you immediately come across a disappearing defect leading to a fatal error.

In this case, the one line code is easier to read than the six line code. Moreover, it is more logical because it is not bound in any way to the need to be inside a loop. I.e. the first case can be easily copied, the second cannot.

If we are talking about a particular case, it can be true, because the given code is almost standard for every EA. But if you take something more complicated, it is difficult to read it when written in one line.

Why listen to curses from outer space from someone who works with your code? ))

 
Ihor Herasko:

Well, who else can you cite as an authority?

It is strange that the notion of authority is touched upon here.

Yes, in MT4 there is a 99% probability that it is, because MT4 is almost buried. But try to pull such a stunt cross-platform and you immediately run into a disappearing defect leading to a fatal error.

Writing in MT5 is identical.

If we are talking about a particular case, it can be so because the given code is almost standard for each EA. But if you take something more complicated, it is difficult to read it when it is written in one line.

And there are also constructions if -> else if -> else. I do not understand why a bool-expression in a conditional operator must be given in the most primitive form.

 
Alexey Kozitsyn:

For you the code is understandable. But someone who has just looked through the documentation and seen your code will immediately wonder why the array is of size 8, while the order types in the documentation are only 6.

And personally, I also find it easier to read conditions if they are separated separately, i.e. like this:

I'm also more comfortable than like this:

But I think it's a matter of taste and habit. No one needs to impose or prove anything.

On the other hand, I agree with you that:

And I think it's logical, and I don't remember any other times.

Those are the key words.

Personally, I'm annoyed by the spelling of continue at all.

What's the point of them???? If you read

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == m_nMagicNumber)

everything reads russian:

If the order is selected and the order symbol is "ours" and the magician is also ours... then we do everything in curly braces.

But that doesn't sound very Russian:

If the warrant is not selected, fuck off...

If the warrant symbol isn't ours, fuck off...

and so on.

How many times do we have to send ourselves there...................

Apparently this made sense in mql3. It was a way to reduce the time to check the condition. Then all the conditions are checked from the beginning to the end. However, the situation has been solved long ago; if the check encounters an unfulfilled condition, further checks stop. And all these tricks make absolutely no sense.

 
Alexey Viktorov:

These are the key words.

Personally, I'm annoyed by the spelling of continue at all

What's the point of them???? If you read

it all reads in Russian:

If the order is selected and the order symbol is "ours" and the magician is also ours... then we do everything in curly braces.

But that doesn't sound very Russian:

If the warrant is not selected, fuck off...

If the warrant symbol isn't ours, fuck off...

and so on.

How many times do we have to send ourselves there...................

That must have made sense in mql3. It was a way to reduce the time of checking a condition. At that time all conditions were checked from the beginning to the end. However, the situation has been solved long ago; if check has stumbled upon a condition not being fulfilled, further checks will stop. And all these tricks make absolutely no sense.

You've agreed yourself that it's a matter of habit. I, for example, am annoyed by unnecessary nesting, I always remove it with return, continue. And instead of "go to hell" it's easy to get used to reading "conditions 1 and 2 are fulfilled":

if(!condition1 || !condition2)
   continue;
 
Vladislav Boyko:

For example, I'm annoyed by unnecessary nesting, I always remove it using return, continue

I'm irritated by"Boolean negation NOT(!)", it not only takes a CTs cost, but reading a logical expression turns into reading "backwards and forwards" )))

I always return "true" in bool functions as the most expected response, as an example: I check server availability this way:

bool ServerDisable(int count=10){
   for(int i=0;i<count;i++){
      if(IsConnected())
         if(IsTradeAllowed())
            if(!IsTradeContextBusy()){RefreshRates(); return(false);}
      Sleep(157);
   }
   Print(__FUNCTION__," Торговый сервер не отвечает");
return(true);}

I call it quite readable and logical:

if(ServerDisable()) return;

if server is busy - exit, I usually use in trade functions, there's no need to bother the server with requests because it's busy

as they say - it's a matter of taste, but as you know: tastes differ ))))

Reason: