Embedded Systems Design - March 2008 - (Page 50) 0308esd.p49to52 2/14/08 1:02 PM Page 50 break points (www.hpl.hp.com/ complexity analysis. Think of cyclomatic complexity like the hpjournal/pdfs/ That rule has been IssuePDFs/1989canary in a mine. It’s an early warning that the interpreted in a lot 04.pdf). But it’s imfunction may be difficult to maintain and error of mostly dysfuncpossible to define a tional ways and is prone. single value of it that often used to excuse separates good funcmany other sorts of tions from bad ones. constructs. It’s betThink of cyclomatic complexity like the canary in a mine. ter to say: “No function can exceed 10, except in cases It’s an early warning that the function may be difficult to where the resulting code would be excessively hard to maintain and error prone. understand or maintain.” Long ago, George A. Miller (“The Magical Number Over the years, the following rules of thumb have Seven, Plus or Minus Two: Some Limits on Our Capacity been observed: for Processing Information,” Psychological Review, 63 (1956), 81-97) showed that humans can typically keep a v(G) Risk maximum of five to nine things in short-term memory. 1 to 10 A simple function That’s a pretty good place to start: why write functions without much risk that are more complex than we can understand? 11 to 20 More complex, McCabe suggested that 10 is probably a good limitmoderate risk ing value for v(G), and that number is certainly the most 21 to 50 Complex, widely used. It’s comfortingly close to Miller’s 7±2 as high risk well. McCabe pointed out an important exception: 51+ Untestable, switch statements can generate very high-complexity very high risk metrics even in cases where the logic is pretty simple, so he suggested exempting functions with switches from And: Can CMX Really Put TCP/IP On My Little Ole 8-bit Chip? Yes, Ma’am, CMX has been doing amazing things with RTOSes and TCP/IP stacks for many years now. If you haven’t visited us in a while, you are missing a lot of cool, new technology that is economical, royalty free, and comes with source code. v(G) Risk of injecting another bug when modifying the code 1 to 10 . . . . . . . . . . . . . . . . . . 5% 20 to 30 . . . . . . . . . . . . . . . . . 0% >50 . . . . . . . . . . . . . . . . . . . 40% Around 100 . . . . . . . . . . . . 60% For a variety of reasons, few companies routinely practice code inspections, which are the best tool we have for cheaply and effectively eliminating bugs. But one can use the complexity metric to flag risky routines that should get an inspection. I recommend sending, at the very least, any function that scores over 10 through an inspection. Validated Software (validatedsoftware.com) certifies firmware to various safety-critical standards. Scott Nowell there tells me that on one recent project the code had an average v(G) of 4.7, suggesting that great code is composed of simple functions. So how do typical packages stack up? Here are some results from my lab using the RSM tool (described later). Apache 2.2.8, the open source web server, is composed of 5,752 functions with an average cyclomatic complexity of 6.04. Although 61 functions exceed 50, just under 5,000 are below 10. One scored a terrifying 725! That function— a single function, mind you—is 2,700 lines long with 145 cases and 353 if statements. If a v(G) of 100 indicates an It might just put the sparkle back in your eyes! CMX RTOSes and TCP/IP Stacks Support Most 8-, 16-, 32-bit Processors and DSP’s. 12276 San Jose Blvd Jacksonville, FL 32223 Ph: 904.880.1840 Fax: 904.880.1632 email: cmx@cmx.com www.cmx.com 50 MARCH 2008 | embedded systems design | www.embedded.com http://www.hpl.hp.com/hpjournal/pdfs/IssuePDFs/1989-04.pdf http://www.hpl.hp.com/hpjournal/pdfs/IssuePDFs/1989-04.pdf http://www.validatedsoftware.com http://www.cmx.com http://cmx.com http://www.cmx.com http://www.embedded.com
Table of Contents Feed for the Digital Edition of Embedded Systems Design - March 2008 Embedded Systems Design - March 2008 Contents #Include Programming Pointers Designing DSP-based Motor Control Using Fuzzy Logic Hardware/Software Verification Enters the Atomic Age Efficient CRC Calculation with Minimal Memory Footprint Programming Your Own Microcontroller Advertising Index Break Points Marketplace Embedded Systems Design - March 2008 Embedded Systems Design - March 2008 - (Page BB1) Embedded Systems Design - March 2008 - (Page BB2) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page Cover1) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page Cover2) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page 1) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page 2) Embedded Systems Design - March 2008 - Contents (Page 3) Embedded Systems Design - March 2008 - #Include (Page 4) Embedded Systems Design - March 2008 - #Include (Page 5) Embedded Systems Design - March 2008 - #Include (Page 6) Embedded Systems Design - March 2008 - #Include (Page 7) Embedded Systems Design - March 2008 - #Include (Page 8) Embedded Systems Design - March 2008 - Programming Pointers (Page 9) Embedded Systems Design - March 2008 - Programming Pointers (Page 10) Embedded Systems Design - March 2008 - Programming Pointers (Page 11) Embedded Systems Design - March 2008 - Programming Pointers (Page 12) Embedded Systems Design - March 2008 - Programming Pointers (Page 13) Embedded Systems Design - March 2008 - Programming Pointers (Page 14) Embedded Systems Design - March 2008 - Programming Pointers (Page 15) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 16) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 17) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 18) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 19) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 20) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 21) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 22) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 23) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 24) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 25) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 26) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 27) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 28) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 29) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 30) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 31) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 32) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 33) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 34) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 35) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 36) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 37) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 38) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 39) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 40) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 41) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 42) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 43) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 44) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 45) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 46) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 47) Embedded Systems Design - March 2008 - Advertising Index (Page 48) Embedded Systems Design - March 2008 - Break Points (Page 49) Embedded Systems Design - March 2008 - Break Points (Page 50) Embedded Systems Design - March 2008 - Marketplace (Page 51) Embedded Systems Design - March 2008 - Marketplace (Page 52) Embedded Systems Design - March 2008 - Marketplace (Page Cover3) Embedded Systems Design - March 2008 - Marketplace (Page Cover4)
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.