[vc_row][vc_column width=”1/1″ animate=”false” effect=”fade” margin_b=”true” text_align=”left” pl=”40″ pr=”40″ pt=”0″ pb=”0″][vc_column_text pl=”0″ pr=”0″ pt=”0″ pb=”0″]
The code contains too many lines containing several instructions
[/vc_column_text][nz_btn text=”Software Agility” link=”http://casthighlight.wpengine.com/category/product/indicators-methodology/code-insights/software-agility/” target=”_self” animate=”false” animation_type=”ghost” color=”pink” size=”small” shape=”rounded” type=”normal” hover_normal=”fill” hover_ghost=”fill”][nz_btn text=”Code Readability” link=”http://casthighlight.wpengine.com/category/product/indicators-methodology/code-insights/software-agility/code-readability/” target=”_self” animate=”false” animation_type=”ghost” color=”black” size=”small” shape=”rounded” type=”ghost” hover_normal=”fill” hover_ghost=”fill”][vc_empty_space height=”32px”][vc_separator color=”grey” align=”align_center”][vc_column_text pl=”0″ pr=”0″ pt=”0″ pb=”0″] This code insights verifies that the source code doesn’t contain multiple instructions in a single line. Depending on the density of cases of multiple instructions per line of code, and based on specific threshods, Highlight counts penalty points for the scanned file.
The following patterns are used to detect them:
– more than one “;”
– “{” … statement … “;”
– statement … “; }”
– “;” and one of the following keywords: while, for, foreach, if else, switch, try, catch, finally, do…
– more than one keyword listed above, except for “else if” [/vc_column_text][vc_separator color=”grey” align=”align_center”][vc_column_text pl=”0″ pr=”0″ pt=”0″ pb=”0″]
Why you should care
Having multiple instructions in one line of code remarkably decreases readability of your software. In addition to making source code harder to understand, developers may miss some important instructions – because they’re in the middle of others – that could impact the software execution (e.g. if(today == “Monday”) { echo “Have a good week”; formatUserDrive(); echo “and a great week-end too!”; }
References:
https://softwareengineering.stackexchange.com/questions/104066/single-line-statements-good-practices
https://www.quora.com/When-is-it-appropriate-to-have-multiple-Java-statements-on-one-line [/vc_column_text][vc_separator color=”grey” align=”align_center”][vc_column_text pl=”0″ pr=”0″ pt=”0″ pb=”0″]
CAST recommendations
Although in some cases there may be a good reason to have more than one instruction per line (e.g. very simple code like “if(found) { break; }”), it is generally agreed by the developer community that each instruction should have its own code line.[/vc_column_text][vc_separator color=”grey” align=”align_center” style=”” border_width=”” el_width=””][vc_column_text pl=”0″ pr=”0″ pt=”0″ pb=”0″]
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.[/vc_column_text][nz_btn text=”How it works” link=”http://casthighlight.wpengine.com/how-it-works/” target=”_self” animate=”true” animation_type=”ghost” color=”black” size=”small” shape=”rounded” type=”normal” hover_normal=”fill” hover_ghost=”fill” icon=”icon-cog”][nz_btn text=”Features & Analytics” link=”http://casthighlight.wpengine.com/outputs-analytics/” target=”_self” animate=”true” animation_type=”ghost” color=”pink” size=”small” shape=”rounded” type=”ghost” hover_normal=”fill” hover_ghost=”fill” icon=”icon-stats”][/vc_column][/vc_row]
Leave a Reply