I'm no guru, but here, in my humble opinion, declaring variables in a loop is a HUGE deal (and it's no longer a HUGE deal) !!!
One thing is a function, even a local piece of code, but loops....
I may be wrong ))))))))
Not possible, but definitely wrong. Just one example: You loop through the open positions. You get a position ticket, use it to get other position properties. There are two variants, either in each function of getting position property insert PositionGetTicket(i) or write it in a variable once and use it. But after exiting the loop nobody needs this ticket... Why declare this variable in the body of the OnTick() function or even more interesting at global level?
I think the first option, because there is no extra variables, they not only use memory, but for me, clutter the code - read more, but it depends on the functions you call imho, if the function is rarely used, then sometimes it will be more readable, if you declare a variable with a name in the sense of the task.... all in all, this is a creative problem ))))
but generally, don't listen to them, write as you like - use the language for your own convenience
SZZ: look at examples from mikrosoft, the style mostly - declarations at once when using variables, basically get local scope, but without fanaticism ))
void SimpleImage::CalculateDrawingRect()
{
// Load our bitmap if necessaryif (nullptr == m_bitmap)
{
if (FAILED(LoadBitmapFromShellItem()))
{
return;
}
}
// Calculate bitmap rectanglefloat boundingWidth = m_boundingRect.right - m_boundingRect.left;
float b oundingHeight = m_boundingRect.bottom - m_boundingRect.top;
float w idth = Direct2DUtility::GetRectWidth(m_clipRect);
float h eight = Direct2DUtility::GetRectHeight(m_clipRect);
if (!m_isHorizontal)
{
// Swap width and height to calculate boundariesfloat widthTemp = width;
width = height;
height = widthTemp;
}
if (width > boundingWidth)
{
// Width is larger than bounding box. Scale width to fitfloat scale = boundingWidth / width;
width *= scale;
height *= scale;
}
This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
Just met a bunch of people who think that the compiler zeroes in on local variables just like it does on global variables.
And the compiler doesn't give out varnings.
It does, string and print are no indicator of working with variables
'tst.mq5' tst.mq5 1 1
possible use of uninitialized variable 'c' tst.mq5 16 10
possible use of uninitialized variable 'e' tst.mq5 20 17
code generated 1 1
0 error(s), 2 warning(s), 526 msec elapsed 1 3
time = 1018
sum = 894782460
time = 371
sum = 894782460
I don't know why, but μl overtakes strongly (and the more intricate rand() variants).
And for me it's obvious - take it out of the loop.
Just met a bunch of people who think that the compiler zeroes in on local variables just like it does on global variables.
And the compiler doesn't give out any warrants.
Or .... I don't know. I get it to swear at every chance I get.... ))))))
Or .... I don't know. I swear like that every chance I get.... ))))))
time = 1018
sum = 894782460
time = 371
sum = 894782460
I don't know why, but μl is way ahead of the curve (and the more intricate rand() variants).
And for me it's obvious - take it out of the loop.
I'm no guru, but here, in my humble opinion, declaring variables in a loop is a HUGE deal (and it's no longer a HUGE deal) !!!
One thing is a function, even a local piece of code, but loops....
I may be wrong ))))))))
You have an obscene version of the compiler)
And I'm happy about that ))))))))))) Although sometimes .... I'd rather he didn't say anything )))))))))))))))))))))))))))))))
If this is a debate - I want to ask the Guru.
Which is "correct" (optimal and readable):
Or
If the order of i is indifferent?
I'm no guru, but here, in my humble opinion, declaring variables in a loop is a HUGE deal (and it's no longer a HUGE deal) !!!
One thing is a function, even a local piece of code, but loops....
I may be wrong ))))))))
If this is a debate - I want to ask the Guru.
Which is "correct" (optimal and readable):
Or
If the order of i is indifferent?
I think the first option, because there is no extra variables, they not only use memory, but for me, clutter the code - read more, but it depends on the functions you call imho, if the function is rarely used, then sometimes it will be more readable, if you declare a variable with a name in the sense of the task.... all in all, this is a creative problem ))))
but generally, don't listen to them, write as you like - use the language for your own convenience
SZZ: look at examples from mikrosoft, the style mostly - declarations at once when using variables, basically get local scope, but without fanaticism ))
https://github.com/microsoftIf this is a debate - I want to ask the Guru.
Which is "correct" (optimal and readable):
Or
If the order of i is indifferent?
If indifferent then.
int i = Bars();
while(i-- > 0)
{
// code
}
.