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
Declaring variables is advised because it is considered to be good programming practice but it also allows the code to be more resilient. Preventing spaghetti code is absolutely key to progress, otherwise it can lead to confusion and frustration in the development teams. [nz_btn text="Production Risk" target="_self" animate="false" animation_type="ghost" color="pink" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/innovation/" icon="icon-office"][nz_btn text="Spaghetti Code" target="_self" animate="false" animation_type="ghost" color="sandy_brown" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="fill" link="https://en.wikipedia.org/wiki/Spaghetti_code"]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 1NUM 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/[nz_btn text="Style Guide" target="_self" animate="false" animation_type="ghost" color="turquoise" size="small" shape="rounded" type="ghost" hover_normal="opacity" hover_ghost="fill" link="https://github.com/Kristories/awesome-guidelines" icon="icon-book"]How we detect
This code insight showcases a non-existing variable is implicitly declared when assigned. It is considered good practice to declare the variable before proceeding any further.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.
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_vardecl-always-declare-variables/
https://doc.casthighlight.com/alt_vardecl-always-declare-variables/
Comments