The code contains too many lines containing several instructions

The code contains too many lines containing several instructions

[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"] 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"

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

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.

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.[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"]
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_multinst-code-contains-many-lines-containing-several-instructions/
Have more questions? Submit a request

Comments

Powered by Zendesk