Why you should care
It is important to remember that KSH uses variables and parameters to store values. It also supports data types and arrays. The four data types KSH supports include string, integer, float and array. If a data type is not defined then KSH assumes the variable is a string.
Usually KSH variables can be declared as a local variable because these variables will be considered as global in scope otherwise. Having too many global variables can cause unspecified functions which leads to spaghetti code that ends up being hard to manage and collaborate with. This in turn leads to a buggy and unproductive code.
Business Impacts
CAST Recommendations
CAST recommends having declared variables as local variables because it allows for code to have specified functionalities and to prevent spaghetti code from occurring.
Here are a few examples below of how to declare variables –
variable= – declares variable and set it to null
$ typeset —i NUM=1 $ print $NUM 1
NUM is set to an integer=type variable and assigned a value.
Whenever spaghetti code arises, it is important for the development team to take a few steps back, re-evaluate the project’s functions and goals. Usually the company has a style guide but it may not be followed because it does not have the necessary guidelines that can used for current projects. In such cases, the guides should be updated to meet the needs of developers and newer projects.
References
https://docs.oracle.com/javase/tutorial/java/javaOO/variables.html
www.informit.com/articles/article.aspx?p=99035
https://www.acrolinx.com/blog/companys-style-guide-measure/
How we detect
About CAST and Highlight’s Code Insights
Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.