Single quote strings keeps code consistent and productive

[nz_btn text="Software Resiliency" link="http://casthighlight.wpengine.com/software-resiliency/" target="_self" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="normal" hover_normal="fill" hover_ghost="fill" icon="icon-dashboard"][nz_btn text="Code Reliability" target="_self" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="screen" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/code-insights/software-resiliency/code-reliability/" icon="icon-code"]

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"}';  

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.[nz_btn text="Production Risk" target="_self" animate="false" animation_type="ghost" color="pink" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/innovation/" icon="icon-office"]

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/

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="See features" link="http://casthighlight.wpengine.com/outputs-analytics/" target="_self" icon="icon-stats" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="normal" hover_normal="fill" hover_ghost="fill"][nz_btn text="How it works" link="http://casthighlight.wpengine.com/how-it-works/" target="_self" icon="icon-cog" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="fill"]
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_string-prefer-simple-quotes-strings/
Have more questions? Submit a request

Comments

Powered by Zendesk