Discussion of article "Better Programmer (Part 01): You must stop doing these 5 things to become successful MQL5 programmer" - page 2

 

Good article. The concept of what to do and what not to do is well explained.

Errors in specific examples in this case do not reduce the value of the article, as its task is to help people optimise their work style. This task is solved brilliantly, everything is written as simple and clear as possible.

Thank you, Omega!

 
fxsaber #:

  • The first value of the variable in the loop is wrong.
  • Instead of one if, there are two.
  • string comparison (character) must come at the end.
  • bool expressions are not bracketed.
  • Magic variable is missing in the input functions.
  • The position object was not created.
I didn't see the error the first time until it was published because I didn't code it in the meta-editor but just while writing it, but it's not a big problem because, by the way, all the coding examples used should only have specified
 

Interesting...

fxsaber #:

  • The first variable value in the loop is incorrect.
  • Instead of one if, there are two ifs.
  • string-comparison (symbol) should be at the end.
  • bool-expressions are not marked with brackets.
  • Magic variable is missing in the input functions.
  • The position object is not created.

Becoming a good programmer (part 1): getting rid of five habits to become a better MQL5 programmer

 
Aliaksandr Hryshyn #:

Interesting....


:)
 
Aliaksandr Hryshyn #:

Interesting...

Becoming a good programmer (part 1): getting rid of five habits to become a better MQL5 programmer

This is freelancing, customers most often do not understand the code at all, and bad reviews are not for the quality of the code. I wrote it, the programme did not give profit, so here is the review.

 

A must read for everyone (and the author of the article even more so) : 97 Things Every Programmer Should Know

GitHub - 97-things/97-things-every-programmer-should-know: Pearls of wisdom for programmers collected from leading practitioners.
GitHub - 97-things/97-things-every-programmer-should-know: Pearls of wisdom for programmers collected from leading practitioners.
  • github.com
Pearls of wisdom for programmers collected from leading practitioners. - GitHub - 97-things/97-things-every-programmer-should-know: Pearls of wisdom for programmers collected from leading practitio...
 
Source:
int CountPosByType(ENUM_POSITION_TYPE type)
  {
   int counter = 0;
   for(int i=PositionsTotal(); i>=0; i--)
      if(m_position.SelectByIndex(i))
         if(m_position.Magic()==MagicNumber && m_position.Symbol()==Symbol() && m_position.PositionType()==type)
            { 
                counter++; 
            }
   return counter;
  }

Variant working faster and in my opinion clearer:

int PositionsByType(ENUM_POSITION_TYPE type)
  {
   int counter = 0;
   for(int i=PositionsTotal()-1; i>=0; i--)
   {
      if(!m_position.SelectByIndex(i))
         return (INVALID_HANDLE);

      if(m_position.PositionType()!=type ||
         m_position.Magic()!=MagicNumber ||
         m_position.Symbol()!=Symbol())
         continue;

      counter++; 
   }
   return counter;
  }

1. the error in the loop initialisation is that 1 must be subtracted from the quantity when we do the backtracking.

2. If you could not get the position by the index from the library function, you need to exit the loop with an error and then if you need to process or repeat the function again, otherwise there is a risk of getting an unreliable amount, and you still work with finances, and sometimes there are large amounts in the position, and such a small thing can lead to a loss.

3. First you should check bool variables, then ENUM enumerations and only after that check int, double, string, if the check fails, then immediately go to the next element of the loop.

If you make comparison operations via &&, the programme will necessarily check each condition.

4. The name for the function is also important, it looks better PositionsByType, it seems like a trifle, but when you go to use this function you don't need to go to the library and its table of contents, but just start typing the standard name Positions, and you will have several options for calling PositionsTotal, PositionsByType.....

5. You need to respect the width of the code so that you don't use horizontal scrolling, as this greatly reduces readability and speed of development.


 
You are wrong about that:
"If you do comparison operations with &&, the programme will necessarily check each condition.".
The comparison is performed in order up to the first false.
By the way, in such situations you can also take into account the probability of the condition not being fulfilled.

 
Aliaksandr Hryshyn #:
You are wrong about that:
"If you do comparison operations via &&, the programme will necessarily check each condition.".
The comparison is made in order up to the first false.
By the way, in such situations you can also take into account the probability of the condition not being fulfilled.

Yes, you have corrected me correctly, the check will be performed up to the first false, the main thing is that small data types should be first.

In case the conditions consist of functions, the smallest one should be the first and up to the largest one from the point of view of consumed resources, but without breaking the programme logic...

I use this technique in all my projects, the speed gain is noticeable for a tester in optimisation mode.

[Deleted]  
Vitaly Muzichenko #:

This is freelancing, customers most often do not understand the code at all, and bad reviews are not for the quality of the code. You wrote it, the programme did not give you profit, that's the review.

Do you tell the customer about this in advance, or is money more important?