The code contains too many lines containing several instructions
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.