Discussion of article "Using Pseudo-Templates as Alternative to C++ Templates"

 

New article Using Pseudo-Templates as Alternative to C++ Templates is published:

The article describes a way of programming without using templates but keeping the style of programming iherenet to them. It tells about implementation of templates using custom methods and has a ready-made script attached for creating a code on the basis of specified templates.

Author: Николай

 

I liked the article, although I didn't understand anything.

"That's why the main task solved by templates is still reducing the amount of code typed by a programmer from the keyboard."

Why bother with templates when you can do without copy-paste? And the amount of typed code doesn't bother you at all - well, there will be 300 lines of code instead of 100 - so what's wrong? The main thing is that it works and debugging does not overstress.

And the code will be more transparent without templates.

 
Virty:

I liked the article, although I didn't understand anything.

"That's why the main task solved by templates is still reducing the amount of code typed by a programmer from the keyboard."

Why bother with templates when you can do without copy-paste? And the amount of typed code doesn't bother you at all - well, there will be 300 lines of code instead of 100 - so what's wrong? The main thing is that it works and debugging does not overstress.

And the code will be more transparent without templates.

300 :)

How about 10-20K (and that's taking into account splitting into modules)...? ?

 
Interesting:

300 :)

And 10-20K how about you (and that's taking into account the breakdown into modules).... ?

Is it really 20,000? My God, how do you dig in there? Maybe the algorithm has not been finalised? Such sizes should have been put into libraries long ago. What are you programming? 20,000 lines is 10 programmers for six months of work.
 
Virty:
Is that 20,000? Jesus, how do you dig in there? Maybe the algorithm hasn't been finalised? Such sizes should have been put in libraries long ago. What are you programming? 20,000 lines, that's 10 programmers for six months of work.

As for libraries, I told you - taking into account modularity.

As for 20K, we've seen more. For example, modzli for 1C 7.7 are 50K lines (and this is not their own, but someone else's code).

 
Nikolay, good article. I will definitely experiment, maybe I will like it and use "templates" in MQL5.
 

Forgive me if I don't understand the essence of the task. In C++ there is saving of source code records, here there is not. Function templates in C++ show where you can really save money. "Saving source code" is the key idea.

And generating an obviously excessive amount of source code to make it difficult to work on it later, well, no, please.

Do you need the same function for different data types? MQL5 has method overloading. I have no doubt that you know about it. Especially since changing the type of input data often requires changing the implementation.

And about this:

>>For debugging, of course, you will have to move the file to the directory of the called file or the Include directory. This is exactly the inconvenience of debugging that I was talking about above when I mentioned the disadvantages of pseudo-templates.

You don't need to move anything manually.

#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
void gena() 
  {
   string filename="code.mqh";
   int handle=FileOpen(filename,FILE_WRITE|FILE_UNICODE);
//-- arbitrary code generation
   string st=TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);
   string code="MessageBox(\"Hello World! Now: "+st+"\");\r\n";
//------------------------------
   FileWriteString(handle,code);
   FileClose(handle);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   gena();
   #include "../Files/code.mqh"; //include the generated code
//---
   return(0);
  }

The example is primitive. Inkludes can be inserted inside functions. And all the code in the included file acts within the scope of visibility of the place of insertion. The only thing is that you will have to create an empty code.mqh file in Files to prevent the compiler from swearing. At the first run the code will be created, and at the second run it will include the generated piece.

 

Nikolai, here is a question. Do you have a function that would evaluate a string? I.e. for example:

str="double a=1.5;"

void eval(str);
Print(a); // a=1.5

I need a void eval(str) function, with the result a=1.5.

The article is good, thanks!

 
denkir:

Nikolai, here is a question. Do you have a function that would evaluate a string? I.e. for example:

I need a void eval(str) function, with the result a=1.5.

The article is good, thank you!

I understand that the question is not about evaluation, but about parsing. Parsing is very versatile.

You can write different rules. It all depends on what you want to get.

For example: how should the parser behave in such examples?

"double a=1.5;"
"double a =1.5;"
"double a = 1.5;"
"double a=1.5,b=2.5;"
"double a =1.5,b =2.5;"
"double a = 1.5,b = 2.5;"
"double a = 1.5 , b = 2.5 ;"
you know. I can only recommend you to study the functionality of the string functions section on simple examples. If you will be able to operate functions from memory, you will be able to plan your development based on the possibilities of the functionality. Without thinking about what you can and cannot do. Knowing the possibilities of the functionality, you will have a clear idea which algorithm will be the most suitable for solving your task.
 
Urain:

So I understand that the question is not about evaluation, but about parsing. Parsing is very versatile.

You can have different rules. It all depends on what you want to get.

For example: how the parser should behave in such examples.

you know. I can only recommend you to study the functionality of the string functions section on simple examples. If you will be able to operate functions from memory, you will be able to plan your development based on the possibilities of the functionality. Without thinking about what you can and cannot do. Knowing the capabilities of the functionality, you will have a clear idea what algorithm will be the most suitable for solving your task.
thank you very much for the answer... I will study the question
 
denkir:
thanks so much for the reply... I will study the question
By the way, the logical operations < > > == are defined for strings.
Документация по MQL5: Основы языка / Операции и выражения / Логические операции
Документация по MQL5: Основы языка / Операции и выражения / Логические операции
  • www.mql5.com
Основы языка / Операции и выражения / Логические операции - Документация по MQL5