Styler in the MetaTrader 5 trading terminal - page 5

 
Renat :

Gentlemen, who is the code being written for?


I'm pretty sure it's for other programmers. It is very unpleasant for them to read other people's unformatted code.


It is to solve this very problem that we created the built-in styler function. If you want other people (not you, but other people) to be willing to look through your code, you'd better make it as simple and unambiguous as possible. And the key word here is "people", not "you".


Renat, who was the styler written for?


I'm pretty sure it was written for other users. But it is very unpleasant for them to read code formatted in someone else's style.


It is to solve this problem we suggest extending the regular styler's functions. If you want other people (not you, but other people) want to use your styler, you'd better make it as convenient and customizable as possible. And the key word here is "people", not "you".



Programmers write code not for themselves, though they mistakenly think it's for them. You know it, don't you?



ps: this CodeBase excuse is absurd, what does the embedded styler in the editor have to do with it?

 
komposter :

ps: the excuse about CodeBase is absurd, what does the embedded styler have to do with it...?

When you build, maintain and pay for Code Base yourself, the question will disappear at once. Or do you think everything around is done for free?


Right now, all we are talking about is a principled "it's only bad because it's not customizable" attitude.


Let's move on to specific points - point out which point and why it's not done correctly by the styler.

 
Renat :

Now all the talk is just about the principled stance of "it's only bad because it's not tunable".

I disagree.

I, for example, have the following position - "what we have is not good because it does not meet the generally accepted coding standards. Means of satisfying the result don't matter".


You have a principled position, and not just on this issue.

And you are categorically unwilling to listen to other people's arguments, even though the arguments are quite reasonable and rational.

Let's move on to specific points - point out which point and why it is done wrong by the styler.

Styler does everything correctly. But the result is not as desired (acceptable).
 
TheXpert :

I disagree.

For example, my position is as follows -- "what is not satisfied because it does not meet generally accepted standards for coding. while not satisfied, I will not use, when satisfied, I will use. Means of satisfying the result don't matter".


You have a principled position, and not only on this issue.

And you are adamantly unwilling to listen to other people's arguments, even though they are quite reasonable and rational.

Styler does everything correctly. But the result is not what you want (acceptable).

+1. On all counts.

It only takes a decision to go back to standard styles. They simply do not want to admit the mistakes of adopting a crooked style once in the past.

 
marketeer :

+1. On all counts.

It only takes a decision to go back to standard styles. They just don't want to admit the mistakes of adopting a crooked style sometime in the past.


I don't agree with the "curvature".

It tastes "tastier" and "brighter" to them... Don't argue about it.

And about customisation, they say - back on topic later

;)

 
Sorento :


I don't agree with the 'curvature'.

It tastes "tastier" and "brighter" to them... Don't argue about it.

And about the settings, they say - back to the subject later

;)

What do you mean you don't agree? There are de facto standards you can't disagree with, you just have to follow them. It didn't occur to them to generate reports in their own HTML with a subversion - they did exactly in the standard one. It's the same with style. Programming is a global industry, styles are defined, and MetaQuotes cannot go against the masses with such "innovation".

 

Please specify which item and why it is not done correctly by the styler.


Preferably with a demonstration of formatted pieces of code.

 
Renat :

Please specify which item and why it's not done correctly by styler.

Preferably with demonstration of formatted pieces of code.

https://www.mql5.com/ru/forum/122145, only there tabs are small -- 2 characters, but it's not so crucial, although it's normal 3-4.

The demonstration is in the first post. There is no comma there, it should be as in this sentence.


If you're serious, I can quote excerpts from our corporate style agreement.

Вот это стиль! :) - MQL4 форум
  • www.mql5.com
Вот это стиль! :) - MQL4 форум
 
Renat :

Please specify which item and why it is done incorrectly by the styler.

Demonstration of formatted code fragments would be desirable.


Renat, this is already unsportsmanlike ;)

MQL is YOUR language, there is no standard for it, so you have the right to set YOUR standards. And we will not prove anything to you.

But MQL is a C-like language. And C has several generally accepted standards. Here they are: https://en.wikipedia.org/wiki/Indent_style.

I personally prefer Allman style (bsd in Emacs).

The style puts the brace associated with a control statement on the next line, indented to the same level as the control statement. Statements within the braces are indented to the next level.

while (x == y)
{
something();
{ somethingelse();
}
finalthing();


It seems to me that the problem of defending your own point of view is completely farfetched. You want to see your text formatted like this, be my guest! But there are other people who want to see it formatted differently. These people (who don't have access to the body) are asking you to consider their needs and make adjustments to the formatting so it can be formatted both your way and theirs. Only you - the developers can do this. This is what we are turning to you with this request. You either meet us halfway or send us all back to your standard. Choose your option and announce it.

Indent style - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Indentation is not a requirement of most programming languages, where it is used as secondary notation. Rather, programmers indent to better convey the structure of their programs to human readers. In particular, indentation is used to show the relationship between control flow constructs such as conditions or loops and code contained within...
 

Just a couple of paragraphs to add why I think this question is important and why I think Allman style (bsd in Emacs) is the right one. Let's forget for a while who is used to what and appeal to naked logic.

Why do you need to format text? In order to isolate and divide individual logical blocks in it by this very formatting.


Let's take a look at an ordinary while. It has two logically isolated blocks: the "header" of the loop and the loop body. In order not to mix them up, they have to be placed on separate lines. For this reason, opening parenthesis in the same line as while (for me personally) causes bewilderment (it's like a man half-entering a room - the whole body is in the room and the head is still "left" behind the door).


Now the second question is to push brackets in or not? In principle, parentheses do not refer directly to the header and are rather a part of the loop's body. However, only executable commands should be pushed inside, i.e. something which has its own separate logic. But there is at least one sensible example of a loop without a body:

while ( TradingServerNotAvailable() )
{
}

We simply have nothing to do while the trade server is not available - so we do nothing and the body cycle is empty. In this case, brackets pushed inside look (from my point of view) - a bit strange: right shifted and empty highlighted.

When a loop has a body, it is moved to the right and space on the left is made available for finding pairs of closing parentheses:

while ( TradingServerNotAvailable() )
{
Sleep ( 1000 );
}

This is another reason why opening parentheses should not be placed in the same line as the loop header - they are harder to find there when you look for closing parentheses. In my version, you can clearly see a parenthesis in this position and its counterpart in another line but in the same position. In addition, the line with a single bracket (even without comments!) serves as an additional visual element, highlighting and separating the internal block from the external one.


As you can see: nothing personal - just the logic of the visual perception of the text!


And it's from the point of view of that logic (rather than personal preferences and habits) that the text in the current styler formatting is incomprehensible to me:

// чего вдавлен внутрь кусок кода - в котором кода нет и выделять там нечего
while ( TradingServerNotAvailable() )
{
}
// каждый отступ вправо ассоциируется с новым уровнем вложенности, а здесь визуально ТРИ уровня!
while ( TradingServerNotAvailable() ) // первый уровень
  { // второй уровень
   Sleep(1000); // третий уровень
  }

And if, in GNU-inspired writing, it's just mush.

if ( TradingServerNotAvailable() ) {
  ....
} else { // вот тут в одной строке ТРИ элемента разных блоков: закрытие предыдущего, разделитель, начало следующего :(((
  ....
}

and how can you tell if you haven't lost an opening parenthesis or put an extra closing parenthesis? It's like this:

if ( TradingServerNotAvailable() ) 
{
  ....
}
else
{
  ....
}
Once again: it's not my personal habits or anything else - just the logic of visual perception of the text!
Indent style - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Indentation is not a requirement of most programming languages, where it is used as secondary notation. Rather, programmers indent to better convey the structure of their programs to human readers. In particular, indentation is used to show the relationship between control flow constructs such as conditions or loops and code contained within...