Errors, bugs, questions - page 1332

 
Alexey Navoykov:
Your advice is meaningless in practice. Nobody gives identical names on purpose. The code of local functions lives its own separate life while the external program lives its own life. And the names of external variables can change with time and new external variables can be added.And if after that, suddenly one of hundreds of functions hasa local variable with the same name, what do you think we should rename the global variable? You should not look for excuses for developers' bugs.

I wasn't looking for an excuse for developer bugs, but this bug is easily circumvented by not using the same variable names that are responsible for the input parameters when working in a project. Just change the name in the input parameters, I doubt you have hundreds of variables in your input parameters and need to edit all the code :) the main part of the code is usually written at the entry point of the software and it is not that big, everything is done by function(method) calls. And to functions (methods) there is no difference what name of a variable is passed in input parameters of function.

Of course, if you write code where functions use global variables, then of course, you will have to change a lot of things, but this code is written with absolutely no vision, it is really difficult to modernize.

Although if you look at the developer (MetaQuotes) with a consumer point of view, of course, you want a lot of everything at once :) I would like to work in a terminal that is cross-platform, but the answer to this request will be one - either use what you have or pass it by :)

 
Konstantin Karpov:

Just change the name in the input parameters...

You have a kind of flippant view. Just change it like that... Then some other function will be added to the code where the local variable name matches and you have to change it again, right? An external variable name is not just a bunch of letters, it has a specific meaning. Sometimes you have to think hard to find a concise and succinct name for it, and you say - change it. And all the preset settings, as well as tester and optimizer settings will be lost for this parameter if the name is changed.

Suppose you inserted some function from somewhere outside, perhaps it was not even written by you, so the local variable names there can be absolutely any.

 
Alexey Navoykov:

You have a kind of flippant view. Then some other function is added to the code where the local variable has the same name, and you have to change it again, right? The name of an external variable is not just a bunch of letters, it has a specific meaning. Sometimes you have to think hard to find a succinct and succinct name for it, and you are saying - change it. And all the preset settings, as well as tester and optimizer settings will be lost for this parameter if the name is changed.

Suppose you inserted some function from somewhere outside, perhaps it was not even written by you, so the names of local variables there can be absolutely any.

Do as you see fit, but it looks like you haven't written any big projects.

It makes no sense for me to look at my function definitions, because I have a clear distinction in the style of declaration of global and local variable names. Therefore, I do not encounter such problems as coincidence of global and local variable names. The main thing is that functions work out their logic without collisions. In your case there is one big BUT, if you coincide a name of a global variable with a name of a local variable, expect surprises, which you have already started to clear up.

For example, put an extra _ in the local variable name, for example _iCount. In this case you will never have problems with variables' names, because you will fulfill what you are trying to explain me the second time - variables live in a local scope, where they were created. And no global variable in this case will not introduce ambiguity in the names. And let's close our discussion at this point.

 

Going back to my previous post. MT4/845, Windows7/64 bit, script:

#property strict

double d1 = 2.009745110811111111111111111;
double d2 = 3.654;
double d3;
//---
void OnStart()
  {
   d3=d1/d2;
   Print("AA: d3 = ",d3);
   Print("BB: d3 = ",DoubleToString(d3));
   Print("CC: d3 = ",DoubleToString(d3,8));
   Print("DD: d3 = ",DoubleToString(d3,9));
   Print("EE: d3 = ",DoubleToString(d3,10));
}

Result:


Administration, add in DoubleToString that this function rounds floating point numbers to the specified precision.

 

It is a good idea not to name local and input variables the same way

 
Комбинатор:

It is a good idea not to name local and input variables the same way

In a good way, yes, but sometimes when you fix someone else's code, connect your own libraries to it, and... bam...
 

Try to continue the line in ME in the attached file without spaces

Files:
comment.mq5  1 kb
 
When discussing an issue, is it OK to link to a product on the Market? Or would that be considered advertising and prohibited?
 
Yousufkhodja Sultonov:
When discussing an issue, is it OK to link to a product on the Market? Or would that be considered advertising and prohibited?
Every product has two tabs: Discussion (for those just thinking about buying) and Reviews (for those who have bought). This is where discussions about the product take place.
 

Questionable compilation result after operator ? :

int f()
{
        int array[];
        return ( false ? array : array );
}
void OnStart()
{
        Print( f() );
}
// 0 error(s), 0 warning(s)
Result: 65618 (how did it get like that?) and there should be a compile-time error
Reason: