size=150Code analysis improvements/size
Version P - 16.098.25+
Code analysis was completelly reworked. It is now more transparent and much more helpfull than before.
attachment=1

- Example of "Warning" window of improved code analysis
- Code analysis.PNG (41.05 KiB) Viewed 5475 times
/attachment
attachment=0

- Example of "Variable reference" window of improved code analysis
- Code analysis variables.PNG (23.54 KiB) Viewed 5475 times
/attachment
Code analysis is divided to two parts:
list
*Warnings - list of warning in the script- information about weak points in the variable definition/*:m
*Variable references - list of all variables used in the script, including references/*:m/list:u
bWarnings window/b
Warning windows specify the possible problems in the variables in script.
list
*bW_001: Unused variables:/b This variables are not used anywhere in the main script. However they could be used inside of user function. bSolution:/b remove them from the Table of variables./*:m
*bW_002: Global variable used just in function(s):/b This variable is used just in function, which is not called from the main script and global variable is not inicialized in the function. bSolution:/b Use variables as local in functions which are not called in main script. Than is safe to remove this variables from the Table of variables./*:m
*bW_003: Not initialized variable:/b Value of variable is not initialized, will always have its default value. This is color=#FF0000dangerous variable/color. Can be the source of many bugs. bSolution:/b Inicialize this variable - from Input object or from dialog. Or reconsider if it is even necessary, and than remove it from the script and from the Table of variables./*:m
*bW_004: Conditional assignment:/b Value of variable is not initialized in all code paths. First initialization is on line: XXX, than the variable is used on line YYY. This is potencially dangerous. Variable is inicialized only in some code branch (most often only Standalone run, or some other IF) and than is used in another branch. There is not the assurance of correct setting in some specific case. But sometimes, it is OK (some specific well known cases) bSolution:/b Initialize variable in main script without any conditions or in the dialog./*:m
*bW_005: Variable value assigned just in ValidateInput:/b Value of variable is initialized just in function ValidateInput. It is more Note than Warning. This is the expected type of initialization of variables, which have to come from some master form. Use this W_005 for check, if all variables which should be loaded from the master form are already loaded. If some variable, which should be from the master form, is not in this list, than there is a problem and you should be aware of it and solve it./*:m
*bW_006: Variable used before its value is defined:/b Variable is used before its value is initialized. First use is on line XXX, value is initialized on line YYY. This is color=#FF0000dangerous variable/color. Because the script will use some old unknown value stored in variable, until it is initialized. bSolution:/b Do not use variables before they are initialized!/*:m
*bW_007: Global variable modified in the function:/b Global variable is modified in function at line. This is color=#FF0000dangerous variable/color. Functions should not modify global variables directly. Can be the source of many bugs. Global variables should be modified from functions via return command or out parameters. bSolution:/b Make all variables inside function local and modify global variables only via return command or out parameter./*:m
*bW_008: Variable value assigned in ValidateInput and modified in the script:/b Value of variable is initialized in function 'ValidateInput' and than it is assigned. This is common behaviour for Standalone run variables. Make sure, that assign on line is only in Standalone branches of calculation./*:m
*bW_009: Variable value defined just in dialog:/b Value of variable is defined just by user dialog. It is not assigned in the script. Acceptable only for standalone variables. Make sure, that all these variables or at least assigned in the ValidateInput function or used only in Standalone parts of script./*:m
*bW_010: Variable value defined in the dialog and assigned in the script:/b Value of variable is defined in user dialog and than it is assigned. This variable can not be changed by dialog (it will be white uneditable). It is OK if you want to display value of variable in dialog, otherwise it is nonsence./*:m
*bW_011: Variable assigned, but not used:/b Value of variable is assigned. Than the variable is not used and the assignment is not visible in any layout. It indicates some old, obsolete and not used variable. Removing the variable from the script and Table of variables is recommended./*:m
*bW_012: Assignment just for output:/b Value of variable is assigned. Assignment is visible in some active layout(s) and some non-active layout(s). It indicates variable used just for presentation in layout. Reconsider its removing, if is not visible in any active layout./*:m
*bW_013: Function parameter is not used:/b Parameter is not used in the script. Function have defined more parameters, than is necessary. This parameter is not used in the body of function, therefore it is not necesssary./*:m
*bW_014: Local and global variable with same name:/b Name of local variable in function is the same as the name of the variable in global context. It is allowed, but aware that, if you change the value of variable in global scope, the value will be changed also inside of function. It is not a problem and variable is not necessary in the parameters of function. It is loaded directly from global scope. /*:m/list:u
bVariable references window/b
This window allows fast and simple exploring where and how are variables used and assigned
Pencil icon indicates assign to the variable
Three groups of variables are availabile:
list
*bGlobal:/b Using of all global variables (variables defined in Table of variables)/*:m
*bParameter:/b Using of all parameters of all functions/*:m
*bLocal:/b Using of all local (inside functions) variables/*:m/list:u