Self-learning the MQL5 language from scratch - page 29

 
Реter Konow:
You've filled a novice with useless information.)

Whether the information is useful or not is up to the beginner to decide

Vasiliy Sokolov:

Well said, informative, thank you

 
Alexey Viktorov:

This suggests that you should not flaunt your desires in such a way. Vladimir might as well have asked questions specifically about this or that function and received useful advice, rather than the nonsense of "experts" like learn C++ or learn assembler. You could start by studying punched cards.

I'm in favour of TC studying according to his plan and not "jumping" over his head. All in good time. And one should of course learn MQL's and in the right order. The above philosophy (given by Vasily and me) may help to structure knowledge, but not empty it. And while the student is at the very beginning of learning, he has to try to structure the emptiness according to our philosophical notation.

Go back to the textbook and forget about all that high-minded stuff for the time being.
 
Vasiliy Sokolov:

Moving on:

  • Since there are many events, there are many event handlers. Since events are called inconsistently, their event handlers are called inconsistently as well. Since there is inconsistent calling, event handlers cannot depend on each other, and they cannot depend on each other's data either. The only construct that meets these strict requirements is a function.
  • Functions cannot depend on each other. If one function returns the sum a+b, and the second returns the product a*b, then the result of these two functions will not depend on the sequence of calls. We can call the first function with arguments 3 and 5 and get 8. Then call the second function with the same arguments and get 24. Then swap their calls. The results will be the same. The addition function will always return 8 with arguments 3 and 5. The multiplication function will always return 24 with the same arguments.
  • It is clear from the above that the event handler can only be a function. If a new tick event occurs, this is handled by the OnTick function. If the Start event (a one-time launch of the script) occurs, this is handled by the special OnStart function.
  • This function is universal. This function can handle not only events. The function can return something useful, e.g., the current time. A function can perform complex calculations with the arguments passed to it and return the final result of these calculations as a single value. Finally, a function can be a data provider: You call the function and get the data you need, such as quotes, from it.
  • Internally, MetaTrader consists of thousands of functions, of which around 1500 thousand are kindly made available to users. These are very useful functions. They allow you to check the system time and obtain the data for an instrument you are interested in. The functions are used to send trade orders. You can open ICL manual and see that it consists of functions and their arguments. So MetaTrader, as far as user programmes are concerned, is one big set of functions.
  • Universal functions are not enough. No matter how many new functions are added to the system, there will always be shortage of them. The reason is that everyone has different needs. There is no one-size-fits-all feature for all occasions. The most generic and universal features are already included in MetaTrader and are kindly shared with us. However, user needs are endless. MetaQuotes can't meet the individual needs of 100,000 users of their terminal. Instead, they did something more flexible: they let users create the features they want themselves. The users benefited from this. Instead of using a system function which is not suitable for them, they can write their own function which solves their problem perfectly. No system function is perfect because of its universality.
  • The skill a user is able to write his own functions and understand how they work tells you how skilled a programmer is. If he/she understands that a program is a disjointed set of handlers (in the form of functions) that do not consistently handle incoming events, it is good. If he knows how to write his own functions, that's another plus. If he can combine the work of several functions (both his own and system functions) into a common algorithm, that's another plus for him.
  • If you understand that everything in MetaTrader (the fourth and fifth) is somehow based on functions, functions and functions - everything suddenly becomes clear. Help is no longer presented as a thick book with a bunch of scattered code snippets, but as a guide to the available functions and what they do. Everything else, like data types, arrays, structures, classes, is irrelevant. It's all about supporting functions so they can return something and accept something.

(for now)

Great!!! Vasily, you have a natural talent for teaching. Everything is clear and understandable, especially for those who are at a complete zero. Have you ever thought of writing a book similar to MQL4 Tutorial by Sergey Kovalev, only now it would be called MQL5 Tutorial by Vasily Sokolov?

Do you thinkthis subject matter will give a stimulus to such an initiative, don't you, Vasily?

Regards, Vladimir.

 
Vasily only focuses your attention on some particular aspects, considering them more important than others. For example, Function or Event. Read about functions in the work of S.Kovalev and you will find no less (and even more) detailed and accessible explanations, but without concentrating on them, to the detriment of the other areas. Therefore, you have to read the textbook.

Yes, Vasiliy has written very well, but it's a bit "skewed" by his subjective understanding.

I'm not saying "learn from me, I know how to do it right!", I'm saying "learn from a textbook and get the basics right, not my hastily formulated concepts of what I care about now in the subject".

P.S. However, that's up to you.
 
Реter Konow:
Vasily focuses your attention only on some particular aspects, believing that they are more important than others. For example, a Function or an Event. Read about Functions by S. Kovalev and you will find no less (and even more) detailed and accessible explanation, but without focusing on them, to the detriment of the other areas. Therefore, you have to read the textbook.

Yes, Vasiliy has written very well, but it's a bit "skewed" by his subjective understanding.

I'm not saying "learn from me, I know how to do it right!", I'm saying "learn from a textbook and get the basics right, not my hastily formulated concepts of what I care about now in the subject".

P.S. However, it's up to you.

And you, Peter, can propose you and Vasily to do a good job together and write such a book on MQL5.

Writing a book is the best way to leave a trace in the history of mankind, particularly in the history of programming. Think about it!

Regards, Vladimir.

 
MrBrooklin:

Peter, I propose you and Vasily to do a good job together and write such a book on MQL5.

Writing a book is the best way to leave a mark onhuman history, particularly in the history of programming. Think about it!

Regards, Vladimir.

Thanks for the suggestion, but Vasiliy easily "beats" me to the classical approach, which is needed in such a book. I can offer only abstract understanding of Object and Environment in their dynamic interaction through the prism of programming, but it will be the final chapter. ))))
 
Реter Konow:
Thanks for the offer, but Vasily easily "beats" me to a classical approach, which is exactly what I need in such a book. I can offer only abstract understanding of Object and Environment in their dynamic interaction through the prism of programming, but it will be the final chapter. ))))

I see. Now I would like to know Vasily's opinion on my book proposal.

I am currently studying his article "Universal Trading Expert Advisor: Working with Custom Trailing Stops (Part 6)".

Sincerely, Vladimir.

 

Continued at

It was clear from the post above that the focus was on functions. Everything was devoted to them and nothing but them. One might think that this is an obvious subjective bias or some arcane "philosophy". However, there is no philosophy here. And such attention to functions is not accidental. The point is that in programming, function is of fundamental importance. Moreover, the function is a very important and fundamental notion in mathematics. In the 20s of the last century, Alonzo Church developed a system of calculus based on functions. This was called lambda-calculus. This system formalized the notion of calculability and tightly bound computer calculations and mathematics. The leading programmers of the world developed so-called functional programming languages based on lambda-calculus, in which functions take the leading place. For example, in a functional Haskell programming language, there is not even a for loop or something similar. Instead, it is proposed to call a function in a special way, recursively, to calculate the desired value. It can be proven that with only functions and no assignment, it is possible to write a Turing complete programming language. This is a language that would allow to write everything that is possible in any other turing-complete language, such as procedural or OOP language.

MQL is not a functional language, but rather a procedural one, extensible by classes, with strict typing and rich subject-oriented API (in the form of the same functions, oh surprise). On the other hand, the theory of functions is based on a solid mathematical foundation and offers simple and effective patterns of using any programming language where there are functions, so it is at least not far-sighted to abandon functions and mathematical basis behind them. This is why I pay so much attention to functions. It doesn't matter how well you understand the array design, or if you make a mistake with a certain data type. This can be quickly fixed and corrected. But if you don't understand functions and how they are related, you won't even become an average programmer.

Thus, to learn how to normally prog, ie linearly over time to expand the functionality of your program, you need to learn the following:

  • Clearly (if not thoroughly, but clearly need to) represent the event model of MetaTrader 4.5.
  • Know how to work with the system functions. Summarize their results in their own functions. Combine the calls of system functions into your own functions.
  • Being able and fond of writing your own functions.
  • Be able to understand function call chains: e.g. when function a() calls function b(), and b() calls c() and e() calls function c().
  • Know how to write clean functions and understand why you should write clean functions. I will explain what a pure function is later.

Functions seem simple. "What's there to learn. You just need to read a paragraph here, and that's all. And then arrays, for, while..." - No, they're not. Functions do seem simple (and that's fine). But for them to really solve tasks efficiently, functions must have certain properties and be combined with each other in a certain way. How to do all this perhaps I will write later.

 
MrBrooklin:

I see. Now I would like to know Vasily's opinion on my book proposal.

I am currently studying his article "Universal Trading Expert Advisor: Working with Custom Trailing Stops (Part 6)".

Sincerely, Vladimir.

No. There will be no book. Maybe some articles. But not in the nearest time for sure.

 
MrBrooklin:

Peter, I can suggest you and Vasily to do a good job together and write such a book on MQL5.

I don't think so. My views with Peter and I are too different. You can take a look at some of our codes to see how different they are.)