Single quote strings keeps code consistent and productive

Software ResiliencyCode Reliability

Single quote strings keeps code consistent and productive

This code insight counts a violation each time a string is enclosed with double quotes, except if the string contains single quotes within double quotes.

bad:

“it is a bad string”
“it is a \”bad\” string”

good:

“it ‘ s a good string”

var JSONObject=’ {
“name”:”John Johnson”,
“street”:”Oslo West 555″,
“age”:33,
“phone”:”555 1234567″}’;

 

5362

Why you should care

It is helpful to keep consistent during development so that bugs and miscommunication can be prevented.  Single-quotes (‘) are preferred to double-quotes (“) because it is more consistent.  It is important to avoid mixing the types of quotes because that would result in the code from functioning properly and inefficiently.

An exception should be noted that double-quotes (“) are used to writing JSON as it’s libraries do not support single-quotes (‘).  This is helpful when creating strings that include HTML or to generate JSON.

Business Impacts

Keeping consistent during development is important because preventing possible bugs and miscommunication between the team helps the code in being resilient which maximizes its’ productivity.

Production Risk

CAST recommendations

CAST recommends keeping your code consistent because that engenders healthy programming and more collaborative development which is reflective of how programming has changed in the more recent years as its taken a more Agile-based approach.  Inconsistent code has the opposite effect and ill-advised, hence keeping single quotes can be one of the many steps towards ensuring your code is productive.

References

https://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript

http://www.agile-process.org/

5362

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.

See featuresHow it works