D
dbeavon
Guest
>> ... define them local... Yes, it is helpful to define variables in proximity to where they are used. I hate it where I'm looking at an ABL program on line 5,000 in a triple-nested loop and someone starts using a variable that is defined waaaay at the top ... so I have to stop what I'm doing scroll up to the beginning of the file. (although tooltips in the IDE help to some extent). I think the problem is that ABL gives you the *false* impression that variables can actually be scoped and initialized in the loop. Whether that makes sense to do (in terms of performance) is another topic. Limiting the scope of variables is more about avoiding bugs and improving the readability of the code. In C#, for example, my variables are scoped as you would expect and it would be possible (theoretically) to reuse variable names in the same method (if they are declared in the scope of a different loop). for (int i = 0; i < 100; i++) { string v_Init = "X"; if(i == 10) { v_Init = i.ToString(); } System.Diagnostics.Debug.WriteLine("Message : " + v_Init); } for (int i = 0; i < 100; i++) { int v_Init = 1; System.Diagnostics.Debug.WriteLine($"Message {v_Init}"); } You can see above that the loop variable (i) can be declared and initialized twice. So can the "v_Init" which is local to every iteration of those loops.
Continue reading...
Continue reading...