MQL5 fails a simple boolean test? If(false) then do it, but it's true, do it anyway? - page 2

 
Le Minh Duc #:
I tried to reproduce the bug but i can't (it worked fine)
Can you post the simplify version of your code?

Thanks, but no need, see my comment just above. I'm satisfied it's a quirk in the debugger, all I care about is the compiler.

 
William Roeder #:

You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

😁

I read "isLongEnabled == false" as "Is long enabled false?" No problem there. I appreciate your style. Too bad you don't appreciate mine. I admit that "isLongEnabled == false" isn't as crisp as "!isLongEnabled", but it's clearer. I work fast, scan code fast, and for me, clarity trumps concise or elegant every time. I don't have the luxury of interrupting my train of thought to unscramble the equivalent of "if(not is long enabled)". "if(is long enabled false)" is way more intuitive. Plus, it's so easy to miss those "!" marks, they just blend in like an I. "!I", said the fox!" 😆

 
William Roeder #:

You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

I wont code in that way for sure. I did this because I wanted to reproduce the bug
 
William Roeder #:

You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

I have fun razzing you, William, but I can tell you're a good coder, and you're smart. Don't let my ribbing give you the impression I'm not benefitting from your contributions!

I'm honestly wondering what you would do with this code. "bDo___" switches trigger logic paths that create data. "bNoPsnYet" is a state variable. It's true until the code "creates" the first "position", and then it's false for the rest of the run.

   bDoPsnOpn                              = false;
   
   if((bDoDirPvt == true && bNoPsnYet == false) || bNoPsnYet == true)
      bDoPsnOpn                           = true;

How would you write that? I'll bet you've got a simpler way to do it.

What you might not understand about the coding I'm doing at the moment is that it's throwaway code. I just code things the way they occur to mr at the time and make them work to do what I need, and as long as it works, I'm happy. If I were working on production-grade code, it would be another matter. Elegance has a price, and I don't want to pay it for this kind of stuff.

To explain just a bit more: I write code to do research and test the production-grade code that I do care about . Once I've answered the question or verified the results of the code I care about, much of this kind of good-enough-for-present-purposes code never gets used again.