About coding style - page 4

 
Mathemat >> :

Yura, your example with one return, of course, is logical. But pay attention that in this case all ifs are always run, unlike the case with many return, when the exit from the function is obtained immediately after reaching the string with the condition.

ForexTools, thanks, I've adopted your ideas on formatting.

Mathemat, because the conditional operator "if" also has such a gimmick as "else".

if(expression1) operator1;

else if(expression2) operator2;

else if(expression3) operator3;

else operator4;

And then the operator is executed after the first true condition and that's it. All ifs are not run further. If a true condition is found, the corresponding operator is executed and the program continues after this construct (it does not search further in the construct).

 

I'm not arguing, Sergei. I was talking about Jura's design here.

 

There's another interesting question to "spur" the discussion: How much do platform limitations affect the style of writing an MQL program? For example: the code is easier to write, understand/read and maintain if logically isolated calculations are made in separate functions. But each call of a function (especially in an interpreter, like MQL) is a time-consuming operation. A single call is of course not critical, but most of us have to write such things within a loop (for int i=0; i<Bars; i++) etc. And here we start to decide what is more important - nice code (in the form of functions - so that later we understand what we wrote) or speed of its execution (copying of similar fragments - so that your loop could work all the time before the next tick comes).

It is clear that in each case - the decision of the golden mean line is different, but.... Who solves this problem?

 

I posted the results of a short study in the same thread on the first page. With my amount of calculations (it's small) I'm quite happy with the functions - even with one line length. But there are other opinions here in the thread as well.

 
That's not what I mean... I mean how much the coding style is affected by the need to consider the external constraints of the platform (any - not just MT)
 

It probably has an effect. I used to consider the ancient Trubo Pascual language as ideal. There it is possible to structure functions, i.e. declaration of functions in functions. C doesn't allow for that. And this is exactly what I'm trying to do now, but essentially on the C platform. Of course, this is only an outward appearance.

More precise now, Sergei?

 

Раньше я считал идеальным древний язык Трубо Паскуаль. Там есть возможность структурирования функций, т.е. объявление функций в функциях.

How the hell is that? Personally, I started learning programming languages in my time with C. Now I know two of them: C and C++. And I must say, I'm not attracted to study any other languages at all. Why do I have to declare function in function? Personally, as I grew up only in C and C++, I don't understand this method.

 
C-4 >> Why do you need to declare a function in a function? >> Personally, as I grew up only in C and C++, I don't understand this method.

But I do understand it now. If I have functions up to the sixth call order, it's not always convenient for me to lump all the functions of different call orders into one pile. It loses the overall view of the call structure. And in Trubo Pasqualee, it's all convenient with this: a few main functions that perform key processing, and all the small sub-functions are hidden inside.

But it's probably a matter of habit. I haven't written anything in it for a long time - and I don't really regret it.

 
C-4 >> :

Why do you have to declare a function in a function? Personally, as I grew up exclusively in C, C++ I don't understand this method.

"There are many things in the world, friend Horatio, which our wise men have never dreamed of" ;)

There's a beauty to it - encapsulation in encapsulation, so to speak. But seriously, it's a really useful tool, if you use it wisely, just like everything else.

Mathemat I used to think that the ancient Trubo Pascual language was perfect.

I'm thinking to return to it, at least in the form of DLL in Delphi. I'm tired of working in MQL for making simple but necessary things (for example, trivial dialog with trader).

 

- What is the strength, Brother!?

- Strength is in the Classes, Brother!

I don't think anything better than classes has been invented yet. Declare private functions inside the class, and public functions to work with it. It's nice and powerful. Inherit functions and variables, think through the hierarchy. Encapsulate data by creating complex data structures. Process the data using the universal algorithms from the library of standard templates. Frankly speaking, encapsulation is very poor in MQL4. You have to keep different types of data separately, which leads to errors. Often we have to watch the indexing of arrays (a terribly annoying error). I think this will be stopped in MQL5.

Reason: