{"id":402,"date":"2012-01-19T15:03:10","date_gmt":"2012-01-19T23:03:10","guid":{"rendered":"http:\/\/angryweasel.com\/blog\/?p=402"},"modified":"2012-01-19T15:03:10","modified_gmt":"2012-01-19T23:03:10","slug":"in-search-of-code-quality","status":"publish","type":"post","link":"https:\/\/angryweasel.com\/blog\/in-search-of-code-quality\/","title":{"rendered":"In search of code quality"},"content":{"rendered":"<p>I\u2019ve been thinking recently about what \u2018code quality\u2019 and what the phrase means. How does someone identify the difference between low quality code and high quality code (or medium quality code)? <\/p>\n<p>In my quest for knowledge, I discovered a few interesting things.<\/p>\n<p>I discovered the Spinellis book, <em>Code Quality: The Open Source Perspective<\/em>. I haven\u2019t read this yet, but I ordered it, and looks like it will be interesting.<\/p>\n<p>I found an article on coupling metrics on the IBM site. The reading here was good, as I discovered they have a <a href=\"http:\/\/www.bing.com\/search?q=site%3Aibm.com+%22in+pursuit+of+code+quality%22&amp;qs=n&amp;sk=&amp;form=QBRE\">series of articles<\/a> on code quality.<\/p>\n<p>I found a few references to analysis tools for JavaScript (some lint-like stuff)<\/p>\n<p>Over in the high brow world of the linkedin groups, I saw a bunch of people referencing code coverage as an indicator of code quality.<\/p>\n<p>Nothing earth shattering, but some good information, and enough to get me thinking about what *I* think code quality is \u2013 and what it is <em>not<\/em>. I think it may be impossible to define code quality in a way that everyone will agree with &#8211; but that doesn&#8217;t mean I shouldn&#8217;t try.<\/p>\n<p>We have <em>some<\/em> metrics that can give us an <em>idea<\/em> about code quality. Quality code doesn&#8217;t have any compiler warnings (ideally at the highest warning level), and it&#8217;s clean from static analysis errors and warnings. Complexity metrics such as cyclomatic complexity (basically, the number of paths through a function), or dependency metrics such as fan-in and fan-out can also be indicators of code quality.  <\/p>\n<p>But \u2013 let\u2019s make it clear that while I\u2019m a (big) fan of those <em>indicators<\/em>, that\u2019s all they are. Running clean with static analysis tools does nothing to ensure code quality \u2013 or product quality either (I <a href=\"http:\/\/angryweasel.com\/blog\/?p=295\">ranted a bit about this<\/a> a few months back). In fact, I guarantee you that I could write (or show you) a piece of software that compiles with the highest warning levels set and passes any static analysis tool with flying colors\u2026that still sucks.&nbsp; <\/p>\n<p>One thing definitely unrelated to code quality is code coverage. All code coverage tells you is what percentage of your code you haven\u2019t tested at all. If you squint and have a few drinks, you can pretend a little that high coverage rates from unit tests prove code quality\u2026but once you sober up you\u2019ll realize that all you have are unit tests that exercise some amount of your code.  <\/p>\n<p>But we <em>can<\/em> go beyond code analysis tools. Testability (can I observe and control program flow), and Maintainability (\u201cAlways code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.\u201d <a href=\"http:\/\/c2.com\/cgi\/wiki?CodeForTheMaintainer\">ref<\/a>) are critical to code quality. Given a good reviewer, <a href=\"http:\/\/www.osnews.com\/story\/19266\/WTFs_m\">Thom Holwerda\u2019s comic<\/a> is also spot on \u2013 <em><strong>the only valid measurement of code quality is WTF\u2019s per minute<\/strong><\/em>. <\/p>\n<p>As I think about this, I find my mind wandering back to Pirsig. Quality and care are two different ways of looking at the same thing. Quality comes from care, so perhaps what I want to measure is the <em>care <\/em>put into coding. The fact that a developer <em>wanted<\/em> to compile at a higher warning level or turn on more static analysis checks, or that they <em>cared<\/em> enough to get the testers input on testability, or a peer\u2019s advice on maintainability may be the best ways to measure code quality of all. <\/p>\n<p>So now, perhaps, I\u2019m in search of a way to discover and measure care.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been thinking recently about what \u2018code quality\u2019 and what the phrase means. How does someone identify the difference between low quality code and high quality code (or medium quality code)? In my quest for knowledge, I discovered a few interesting things. I discovered the Spinellis book, Code Quality: The Open Source Perspective. I haven\u2019t&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-402","post","type-post","status-publish","format-standard","hentry","category-allposts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/comments?post=402"}],"version-history":[{"count":0,"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/posts\/402\/revisions"}],"wp:attachment":[{"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/media?parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/categories?post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/angryweasel.com\/blog\/wp-json\/wp\/v2\/tags?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}