Better Software - May 2008 - (Page 19) Code Craft if(value > threshold) markOutOfLimit(true, timeStamp()); else markOutOfLimit(false, timeStamp()); Listing 5a It simplifies to listing 6b. Similarly, listing 7a represents an impressive attempt to mask a one liner. return mapping.nextAvailable() == INVALID_INDEX; Listing 7b markOutOfLimit(value > threshold, timeStamp()); Listing 5b The separation of declaration from initialization introduces more noise on top of the flag-driven logic. From all this we can extract the delightfully brief listing 7b. Perhaps one of the most pervasive examples of a Booleanto-Boolean converter is the explicit comparison of Boolean results against Boolean literals: if(checkCacheExists() == true) Conclusion In each of these cases it is worth keeping in mind that it is not necessarily ignorance or sloppiness that has led to unnecessary or incorrect logic, and it has nothing to do with the programming language—the examples may have been presented in Java, but they were based on published and production code in a variety of languages. Nevertheless, to paraphrase the author Martin Amis, it is terrible to see a programmer being beaten up by a programming language. Revisit, review, and revise. Truth (or falsehood) will out. {end} The result of explicitly comparing a Boolean against true makes it no truer than it already was. Such tautological phrasing is often a consequence (or a cause) of imperative names that should follow a more predicate-like naming style. Rather than naming the action, name the truth that is being acted on: if(cacheExists()) Names beginning with check, validate, and verify are typ- ical candidates for such renaming. What examples of logic have you seen that, on revisiting, have proven to be either incorrect or reducible to something far simpler? Follow the link on the StickyMinds.com homepage to join the conversation. Flag Waiving Overreliance on flags leads to code with a lot of raw Boolean literals—often an indicator that logic can be revisited and simplified. Consider the example in listing 6a. boolean failed = false; if(message != null) { if(!enqueue(message)) failed = true; } else failed = true; if(failed) throw new MessageEnqueueException(); Listing 6a To load test your website, you could type this: Definitions ! Standard Defines Include "RESPONSE_CODES.INC" Include "GLOBAL_VARIABLES.INC" CHARACTER*512 USER_AGENT Integer USE_PAGE_TIMERS CHARACTER* CHARACTER*1024 cookie_2_0 CHARACTER*1024 cookie_2_1 Timer T_ Code !Read in the default browser user agent field Entry[USER_AGENT,USE_PAGE_TIMER Start Timer T_OBFUSCATED PRIMARY GET URI "http://yahoo.cHTTP/1.1" ON 1 & HEADER DEFAULT_HEADERS & ,WITH {"Accept: image/gif, image/xbitmap, image/jpeg, image/p "application/x-shockwave-flash, application/msword, */*", & or this: www.webperformanceinc.com if(message == null || !enqueue(message)) throw new MessageEnqueueException(); Listing 6b boolean result; int indexOfNext; indexOfNext = mapping.nextAvailable(); if(indexOfNext == INVALID_INDEX) result = true; else result = false; return result; Listing 7a Why code every test case by hand, when our unique software detects and automatically configures the test cases for you – quickly and accurately, then gives you superior reports that are easy to understand? With Web Performance automatic load testing, the time and money you save could increase productivity as much as 500 percent. For more information about how you can increase performance and productivity using Web Performance automated load testing, visit www.webperformanceinc.com www.StickyMinds.com MAY 2008 BETTER SOFTWARE 19 http://www.StickyMinds.com http://www.webperformanceinc.com http://www.webperformanceinc.com http://www.StickyMinds.com
Table of Contents Feed for the Digital Edition of Better Software - May 2008 Better Software - May 2008 Contents Mark Your Calendar Contributors eLightenment Technically Speaking Code Craft Test Connection Management Chronicles Cover Story: It's A Bug! The Chivalrous Team Member Let's Talk Agile Product Announcements 10 Things You Might Not Know About... The Last Word Ad Index Better Software - May 2008 Better Software - May 2008 - (Page Intro) Better Software - May 2008 - Better Software - May 2008 (Page Cover1) Better Software - May 2008 - Better Software - May 2008 (Page Cover2) Better Software - May 2008 - Better Software - May 2008 (Page 1) Better Software - May 2008 - Better Software - May 2008 (Page 2) Better Software - May 2008 - Contents (Page 3) Better Software - May 2008 - Mark Your Calendar (Page 4) Better Software - May 2008 - Mark Your Calendar (Page 5) Better Software - May 2008 - Contributors (Page 6) Better Software - May 2008 - Contributors (Page 7) Better Software - May 2008 - eLightenment (Page 8) Better Software - May 2008 - eLightenment (Page 9) Better Software - May 2008 - eLightenment (Page 10) Better Software - May 2008 - eLightenment (Page 11) Better Software - May 2008 - eLightenment (Page 12) Better Software - May 2008 - Technically Speaking (Page 13) Better Software - May 2008 - Technically Speaking (Page 14) Better Software - May 2008 - Technically Speaking (Page 15) Better Software - May 2008 - Technically Speaking (Page 16) Better Software - May 2008 - Code Craft (Page 17) Better Software - May 2008 - Code Craft (Page 18) Better Software - May 2008 - Code Craft (Page 19) Better Software - May 2008 - Test Connection (Page 20) Better Software - May 2008 - Test Connection (Page 21) Better Software - May 2008 - Management Chronicles (Page 22) Better Software - May 2008 - Management Chronicles (Page 23) Better Software - May 2008 - Management Chronicles (Page 24) Better Software - May 2008 - Management Chronicles (Page 25) Better Software - May 2008 - Cover Story: It's A Bug! (Page 26) Better Software - May 2008 - Cover Story: It's A Bug! (Page 27) Better Software - May 2008 - Cover Story: It's A Bug! (Page 28) Better Software - May 2008 - Cover Story: It's A Bug! (Page 29) Better Software - May 2008 - Cover Story: It's A Bug! (Page 30) Better Software - May 2008 - Cover Story: It's A Bug! (Page 31) Better Software - May 2008 - The Chivalrous Team Member (Page 32) Better Software - May 2008 - The Chivalrous Team Member (Page 33) Better Software - May 2008 - The Chivalrous Team Member (Page 34) Better Software - May 2008 - The Chivalrous Team Member (Page 35) Better Software - May 2008 - The Chivalrous Team Member (Page 36) Better Software - May 2008 - The Chivalrous Team Member (Page 37) Better Software - May 2008 - Let's Talk Agile (Page 38) Better Software - May 2008 - Let's Talk Agile (Page 39) Better Software - May 2008 - Let's Talk Agile (Page 40) Better Software - May 2008 - Let's Talk Agile (Page 41) Better Software - May 2008 - Let's Talk Agile (Page 42) Better Software - May 2008 - Let's Talk Agile (Page 43) Better Software - May 2008 - Product Announcements (Page 44) Better Software - May 2008 - Product Announcements (Page 45) Better Software - May 2008 - 10 Things You Might Not Know About... (Page 46) Better Software - May 2008 - The Last Word (Page 47) Better Software - May 2008 - Ad Index (Page 48) Better Software - May 2008 - Ad Index (Page Cover3) Better Software - May 2008 - Ad Index (Page Cover4) Better Software - May 2008 - Ad Index (Page Survey1) Better Software - May 2008 - Ad Index (Page Survey2)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.