Possible conditional check error - page 2

 
Fernando Carreiro:

You are welcome!

Given that MQL is a strange implementation of "C", like everything MetaQuotes, you will probably never figure out the reason why one gives a warning and the other not. And even if you do, it will probably not make much sense.

It is nice to see the amount of work you are putting into the forum. I would like to say thank you for all your efforts.

I have checked and thought about the differences in this case and I would like to share my assumption about it.

Here is the code, where the warning is showing up: 

bool ret_val_eval(const long chart_id, const string obj_name, const ENUM_OBJECT_PROPERTY_INTEGER obj_prop, const int expected_retval)
{ return(ObjectGetInteger(chart_id, obj_name, obj_prop) == expected_retval); }

void some_func()
{
[...]

    ( (textfield_width != NULL) 
     || ( (obj_list[obj_idx].dynamic)
       //&& (ObjectGetInteger(obj_list[obj_idx].chart_id, obj_name, OBJPROP_XSIZE) != width) )          // (A) This code will give a warning 
       //&& (ObjectGetInteger(obj_list[obj_idx].chart_id, obj_name, OBJPROP_XSIZE)) )                   // (B) This code does not produce a warning
         && (ret_val_eval(obj_list[obj_idx].chart_id, obj_name, OBJPROP_XSIZE, width)) )                // (B) ...as well
    ) && 
    ObjectSetInteger(obj_list[obj_idx].chart_id, obj_name, OBJPROP_XSIZE, width);

[...]
}


This leads me to the conclusion, the assemby code produced by the compiler would have a different operation command sequence as version B.

I guess, without a result its a very similar assembly sequence to the conditional oeprator "?" , which in fact is only one command on the cpu to be executed.

While when comparing two values, a different command is used to do so, therefore a result gets copied by a cpu command into a register for later use.  Since this register never gets referenced within the following code, it is evaluated as an "abandoned value".

All in all, these micro times to save are nice but maybe a little over the edge, sometimes.


But in highly repetitive workloads, like in loops, these differences add up fast.


EDIT: To me, it does not make sense. It is inconsequent.

 
Paul Anscombe:

best way to describe it is:

All the time you are just using boolean logic it is fine, but you have added in a numerical comparison of the value 1 to that of a function output.

The compiler is now saying this is an expression with an answer and you are not using it so it is warning you of that, like you say it still works in practice because each function is processed subject to the logic. 

Thank you for the explanation, as it seems, I did not see this. 

 
Dominik Egert: It is nice to see the amount of work you are putting into the forum. I would like to say thank you for all your efforts.

I have checked and thought about the differences in this case and I would like to share my assumption about it.

Here is the code, where the warning is showing up: 

This leads me to the conclusion, the assemby code produced by the compiler would have a different operation command sequence as version B.

I guess, without a result its a very similar assembly sequence to the conditional oeprator "?" , which in fact is only one command on the cpu to be executed.

While when comparing two values, a different command is used to do so, therefore a result gets copied by a cpu command into a register for later use.  Since this register never gets referenced within the following code, it is evaluated as an "abandoned value".

All in all, these micro times to save are nice but maybe a little over the edge, sometimes.

But in highly repetitive workloads, like in loops, these differences add up fast.

EDIT: To me, it does not make sense. It is inconsequent.

Thank you for your analysis. On a whole I consider MetaQuotes’ way of doing things is very disorganised and ad hoc. One only needs to look at the website itself, and the code in the Standard Library, to see how disorganised and illogical it can sometimes be. From that we can infer that the MQL compiler and MetaTrader’s own code is just as disorganised. It is no wonder that this site, MetaTrader and MQL is always riddled with problems and bugs. When one of them gets fixed, another pops up. On a whole, the quality of MetaQuotes code is not that great.

 

I agree totally and find it interesting, it still works.... 

Imagine it be open source, I mean the client side terminal and the language. - I am sure, security and quality would get a real boost.

Metaquotes could focus on their server infrastructure and let the crowd use the api of the servers.

 
Dominik Egert: I agree totally and find it interesting, it still works.... Imagine it be open source, I mean the client side terminal and the language. - I am sure, security and quality would get a real boost.

Metaquotes could focus on their server infrastructure and let the crowd use the api of the servers.

Unfortunately, they don't understand that way of thinking. I know of someone who recently started doing an open-source interface for the web-terminal and they hit him with a "cease and desist" legal process on GitHub and got his main project closed which did not even have to do with them. They were very forceful and vindictive for something that was actually beneficial for them, but they simply decided that they would not allow it.
 
Fernando Carreiro:
Unfortunately, they don't understand that way of thinking. I know of someone who recently started doing an open-source interface for the web-terminal and they hit him with a "cease and desist" legal process on GitHub and got his main project closed which did not even have to do with them. They were very forceful and vindictive for something that was actually beneficial for them, but they simply decided that they would not allow it.

How is that beneficial ?

They want to have control on client software, seems perfectly normal to me. It's a financial product, can you imagine what would happen if their server is flooded with bad requests or attacked like a website ?

 
Dominik Egert:

I am sorry to say this, but that is untrue.

Go through and test yourself.

The code will conditionally break out into the subfunctions without disturbing the current flow of the function where this code is inserted. - No conditional break within the code flow of the function, if not necessary.


Thats the point of this code, it is valid, it works and it is about 10 times faster than an if-statement. - But thats not the point of discussion here. Its about this code giving a warning, while following does not:



Now tell me, how do you explain that??

I don't see the difference either. The compiler should optimize the expression.

I don't get your point about "10 times faster". What exactly is 10 times faster than what...exactly ?

 
Alain Verleyen: How is that beneficial? They want to have control on client software, seems perfectly normal to me. It's a financial product, can you imagine what would happen if their server is flooded with bad requests or attacked like a website ?

They could easily keep some things closed-source for security reasons (e.g. protocol) and others things could be partially open-source (e.g. language development).

I'm sure that if language development were partly open-source, many bugs would get fixed quickly, and new ideas would be developed.

 
A lot of APIs in the financial sector are open, just think of all the crypto exchanges...

It's good and normal practice to have a secure API. And security on API level as well.

To me, I cannot see the benefit of it being closed source. In contrast, I think an OS Version would benefit all parties.

But that's also only my thinking.

A Linux version would be nice as well as a native Mac Version.

Or think of all the great mobile app adoptions that would happen...
 
Fernando Carreiro:

They could easily keep some things closed-source for security reasons (e.g. protocol) and others things could be partially open-source (e.g. language development).

I'm sure that if language development were partly open-source, many bugs would get fixed quickly, and new ideas would be developed.

For sure, it would be nice, but it will never happen.

Reason: