Wishes for MT5 - page 103

 
A100:

ME5 gives an error when compiling, in my opinion unwarranted.


Fair point - will do.
 

I would like the predefined enum of the form ENUM_XXX to actually be numbered 1, whereas currently it is numbered by default, i.e. 0. The question is not about changing the defaults, but about replacing

enum ENUM_ORDER_TYPE {
        ORDER_TYPE_BUY,
        ORDER_TYPE_SELL, ...
};

it should be

enum ENUM_ORDER_TYPE {
        ORDER_TYPE_BUY = 1,
        ORDER_TYPE_SELL, ...
};

The reasoning is as follows - an example:

MqlTradeRequest request { ...
        ENUM_ORDER_TYPE     type; ...
}

When I analyze request.type value somewhere in code, if it equals 0, I cannot understand whether it was not initialized or was initialized.

request.type = ORDER_TYPE_BUY;

This is the case with most of the predefined enums of the form ENUM_ XXX equivalent of RadioButton and requires an unreasonable amount of complexity to correctly handle the current situation

 
Unfortunately, this is not possible due to maintaining compatibility with the rest of the languages where numbering is from scratch.
 
Renat: Unfortunately, this is not possible due to maintaining compatibility with other languages where numbering is from zero.

What prevents you from writing a neutral identifier as the first member of a predefined enumeration? For example:

enum ENUM_ORDER_TYPE 
  {
   ORDER_TYPE_undefined,
   ORDER_TYPE_BUY,
   ORDER_TYPE_SELL, 
   ...
  };

Both "numbering from zero" will be preserved, and uninitialized variables can be easily evaluated.

 
Yedelkin:

What prevents you from writing a neutral identifier as the first member of a predefined enumeration? For example:

And if you think about the others who are already using the original set of enums? This is not to mention the perplexed look from the entire server complex.

In general, the question is not posed correctly. The developer should not be lazy and force the rest of the world to fit in by self-destructing that very world.

 
Renat: And if you think about others who are already using the original set of enums?

Well, let's think again, "about the rest". What are named constant identifiers for? - Correct, in order to use these identifiers. Moreover, to use these identifiers, you do not need to know what specific values are assigned to enumeration members. Or do you assume that competent programmers use identifiers instead of finding out the default values of enum members, and then make checks based on these default values?

Renat : This is not to mention the perplexing view of the entire server complex.

I.e., it's not hard to implement the suggestion itself, is it?

Renat : Actually this question is put incorrectly. Developer should not be lazy and force the rest of the world to adjust to himself by self-destruction of this very world.

The author of this thread didn't intend to destroy other people's worlds through his laziness. He only made a specific suggestion for improvement. And explained that the zero value turns out to be overloaded.

 

I would like to introduce at least a class as the scope for enum-named elements,

void test1() { enum ENUM_1 { ELEM1 }; }
void test2() { enum ENUM_2 { ELEM1 }; } //ошибка

class A {
        enum ENUM_A { ELEM1 };
};
class B {
        enum ENUM_B { ELEM1 }; //ошибка
};

Rationale for Classes: you have to come up with a unique name that may unexpectedly conflict with library (including third-party) and/or predefined names. Besides, you could use similar names of SL, TP, PRICE, etc. enum elements in several classes simultaneously without fear of conflicts.

Rationale for functions: not critical, but at the same time

 
A100:

We would like to introduce a scope for enum-named elements

Rationale for Classes: you have to come up with a unique name that may unexpectedly conflict with a library and/or predefined name. Also, you could use similar names for SL, TP, PRICE, etc enum elements in several classes at the same time without fear of conflicts.

Rationale for functions: not critical, but at the same time

what about this in C++ ?
 
sergeev:
But what's it like in C++ ?

That's where the legs come from - a paradox, but only now (when there are restrictions), I began to understand why everything was done there :)

Of course, you could do without it - to write a unique name for all classes, but for large programs, and especially for libraries intended for general use - is not an option

 
A100: I would like predefined enums of the form ENUM_XXX actually equivalent to RadioButton to be numbered 1, whereas now they are numbered by default, i.e. 0. The question is not about changing the defaults, but instead of ...

Try this (for "initialisation"):

WRONG_VALUE.

A constant can be implicitly cast to any enum type.

-1