Operators and operands should use appropriate spacing to help readability

Operators and operands should use appropriate spacing to help readability

Software AgilityCode Readability
This code insights verifies that operators and operands are generally surrounded with spaces for better readability. Depending on thresholds CAST has defined, Highlight counts penalty points for the scanned file if missing spaces are too frequent.

Why you should care

Itishardertoquicklyunderstandwordsthatarenotseparatedwithspaces, don’t you think? This is the same for code, especially when defining logical conditions or loops with operators (e.g. &&, ||, >=, etc.) and operands. Adding spaces before and after operators and operands will makes software easier to read.

References:
https://msu.edu/~hanson54/cse232/coding-style.html#ws
http://syque.com/cstyle/ch6.2.htm

CAST recommendations

Ideally, spaces should be added before and after each operator and operand, as shown in the example below.

Very packed IF condition (PHP):

if((!empty($foo)&&$foo>=$number)||($number<=(10*10))) { …

Same IF condition with some spaces:

if((!empty($foo) && $foo >= $number) || ($number <= (10 * 10))) { … 

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