The code contains too many lines containing several instructions

The code contains too many lines containing several instructions

Software AgilityCode Readability
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!”; }


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.

How it worksFeatures & Analytics