Styler in the MetaTrader 5 trading terminal

 

Discussing the MQL5 styler. Started here


I have to look at different code. This includes badly written code.

Good formatting considerably eases code reading.


Therefore, imho, the thing will remain unclaimed by the majority of normal coders due to specific formatting and lack of options.

I propose to either add customization or format in a really common style.

As an option -- make it possible to choose one of 2-3 styles.

Вот это стиль! :) - MQL4 форум
  • www.mql5.com
Вот это стиль! :) - MQL4 форум
 
TheXpert :
Discussing the MQL5 styler


Guano because it's not customizable.

 
TheXpert :

I suggest either adding customisation, or formatting in a really common style.

Alternatively, make it possible to choose between 2-3 styles.

+

 

Actually, the solution is trivial and already implemented by many IDEs.

For each syntactic element ( { ( for function <= if ......) define rules: how many spaces to insert before it and after it and whether a line break is needed before or after it.

Custom settings should be saved to a file and automatically loaded (in priority) when the editor starts.

Документация по MQL5: Основы языка / Типы данных / Целые типы / Символьные константы
Документация по MQL5: Основы языка / Типы данных / Целые типы / Символьные константы
  • www.mql5.com
Основы языка / Типы данных / Целые типы / Символьные константы - Документация по MQL5
 
It would be good to make the styles customisable.
 
sol :
It would be good to make the stylers customisable.


... this is the main question for the developers...

Is it possible to create a customisable styler? i.e. that it is possible - there is no doubt. the question is another, what are the prospects and priorities for considering this wish?

 

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".



Unified styling is important for the MQL5.community, because we collect a huge database of sources in the Code Base. This means that these sources will be read by a huge number of third-party developers and users.


To avoid creating an incomprehensible pile of code, all of the published scripts will be automatically

  1. cleaned by a styler
  2. check for correctness
  3. generate standard screenshots for indicators

It is clear that a unified style is extremely important for solving the global task of training archive maintenance.
 
Rosh писал(а) >>

The logic is that the code is align ed to the nesting level. There is no disagreement here, as we can see.

But opening and closing parentheses are not code, they are design elements, so they slightly exceed the code by one character.


This surprised me. I always thought that a mistake in setting this so called "design element" could drastically change the code. But it turns out that it is not a code element at all. Here is an example:

if (условие) function1(); function2();

и ____________________________________

if (условие) {function1(); function2();}

The compiler said: "it's OK!". But the program will not work. Where is the error? In the layout? Or in the code?

 

Don't cling to words, please.


Imposing strict (even bordering on personal rights) design rules can eradicate killer code of the kind

if (условие) function1(); function2();

In fact, one could argue that weakness on this issue leads the development team into chaos.


It is to reduce this chaos that we have implemented a hard-nosed, unconfigurable styler.


A couple of thousands of scripts in the MQL4 Code Base have passed through the hands of our editors, who would have expressed much harsher views on the styles used. We do not want to go through such a process again.

 
Renat :


Clearly, to solve the global task of training archive maintenance it is extremely important to have a unified style.


100% right.

There has to be a SINGLE style. But! Everyone should and MAY have their own style.

Many people are accustomed to other common styles like VC++ (and I support ForexTools for example, I use it myself).

Why strain the already tortured brains of programmers... It's easier to make this style Customizable. You probably know how it feels when you are looking at a different style of code and you're tempted to change it to your own, native, comfortable style, which you³'ve been using for 15 years...


I think it's not so hard instead of moving brackets { } to the text, and then 1 space away from it - do nothing with them. Keep it level with its parent for, if, ...

 
sergeev :


100% right.

There has to be a SINGLE style. But! Everyone should and MAY have their own style.

If you are writing for yourself, just don't use the regular styler.


Programmers write code not for themselves but mistakenly think they do. You know it, don't you?

Reason: