Discussion of article "MQL5 Programming Basics: Arrays"

 

New article MQL5 Programming Basics: Arrays is published:

Arrays are an integral part of almost any programming language along with variables and functions. Many novice programmers are often afraid of arrays. It sounds strange but it is true! I can assure you that they are not scary at all. In fact, arrays are similar to regular variables.

Multidimensional array

Is it possible that the reason why arrays are seen as something complicated is somehow related to the use of "[" and "]"? These symbols are rarely used anywhere other than in programming when working with arrays, so their location on the keyboard can fade from one's memory and cause discomfort. While in fact, you can easily remember where they are - these two keys are situated next to "Enter" in a logical order: the opening bracket is followed by the closing bracket.

Author: Dmitry Fedoseev

 

Overall not a bad article - better than in programming textbooks, not so dry and quite lucid

I didn't like the example:"Multidimensional array using OOP". It's a simple implementation, but the subsequent work with such a dynamic array is rather "tricky", to me it would be better not to have this example than such a scary construction, imho.

Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Основы языка / Переменные - Документация по MQL5
 
The article is really not bad especially for beginners .
 

It's not badly written, but the article doesn't say a word about CArray and its descendants.

Beginners may think that to work with arrays in OOP style you need to write your own classes, but they have been written long ago.

 

Well, the beginning of the MQL5 programming tutorial is almost finished

The only thing is that the array implementation on OOP looks very strained

 
avoitenko:

It's not badly written, but the article doesn't say a word about CArray and its descendants.

Beginners may think that to work with arrays in the OOP style you need to write your own classes, but they have been written long ago.

By the way, this is a topic for the author to continue the series of articles.
 
avoitenko:

It's not badly written, but the article doesn't say a word about CArray and its descendants.

CArray and all its descendants should be anathematised.

Such things should be written on templates.

Vladix:

The only thing is that array implementation on OOP looks very strained

It is a bit :)

 

Any suggestions on how this array can be done better in OOP?

Trying to get something like in JavaScript:

var ar=new Array();
ar[0]=new Array();
ar[1]=new Array();
ar[2]=new Array();

ar[0][0]=1;
ar[0][1]=2;

alert(ar[0][1]);

The biggest sticking point is that in JavaScript you can put a list into an array at once:

ar[0][2]=Array(131,132,133,134);
alert(ar[0][2][3]);

And there's no way to come up with such a thing here. Therefore, no matter how you look at it. there won't be a good variant.

 
Integer: Any suggestions on how to make this array better on OOP?

I like Yurich 's implementation of dynamic arrays https://www.mql5.com/ru/forum/6729/page3, I don't know how efficient it is in terms of performance, but in terms of code readability it is super.

 

Very good article, for absolute beginner, but also for experimented programmer new to MT5. Only last section "Creating Multidimensional Arrays Using OOP" is of least interest.

Altough, a little error :

Array indexing order can be determined using the ArrayIsSeries() function:

bool series=ArrayIsSeries(ar);

If the array is indexed in reverse order, the function will return true.

This is false. Function to use to know indexing order of an array is ArrayGetAsSeries().

ArrayIsSeries() is used to determine if an array is a TimeSeries.

 

There is only one method that allows you to do a search in an unsorted array

This is not strictly true, have a look at Hash Based Searching Algorithm. But this algorithm is  probably not applicable to trading.