IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New If I didn't know better ...
... I'd say it looks like Ben is getting tired of having to pull out the references after three iterations of talking past each other.


FWIW if something sounds right to me, I don't need the reference. If it sounds wrong, the reference isn't likely to help. (Much.) Counter-intuitive study results notwithstanding.
===

Implicitly condoning stupidity since 2001.
New Good thing that you know better then :-)
Incidentally the measure that I described is due to Tom McCabe. The usual list of key words are, if, while, repeat for, and, and or (or equivalent). The rule of thumb is that 0-5 decision points means that your routine is probably fine. 6-10 indicate that you perhaps should simplify. 10+ is a danger sign.

In both editions of Code Complete you'll find this advice in the Control Structures and Complexity subchapter. In the first edition this is at pp 394-396. In the second edition, pp 456-459. Both versions cite 2 studies (McCabe 1976, Shen et al. 1985) that indicated that complexity and low reliability of code are strongly correlated.

He also reports on a 1989 paper from Hewlett Packard. They used this principle for organizing code on two programs, one at 77,000 lines and the other 125,000 lines. The post-release defect rates rates per thousand lines were 0.31 and 0.02 respectively, both substantially below the norm at HP. (I calculate that this means 24 bugs and 2 bugs.)

In the second edition he claims that his consulting company in the last few years has achieved similar results from this technique.

So not only does this allow you to measure where the bugs are likely to appear, it also allows you to reduce your overall defect rate.

I'd like to update this advice with the point that I think that at least some method calls should be included as "decision points". Depending on the coding style, not all - just the ones that you're likely to actually use polymorphism on. (Simple accessors don't count.) This is just my thinking on the topic though, see [link|http://www.perlmonks.org/?node_id=298755|http://www.perlmonks.org/?node_id=298755] for more detailed discussion.

Cheers,
Ben
To deny the indirect purchaser, who in this case is the ultimate purchaser, the right to seek relief from unlawful conduct, would essentially remove the word consumer from the Consumer Protection Act
- [link|http://www.techworld.com/opsys/news/index.cfm?NewsID=1246&Page=1&pagePos=20|Nebraska Supreme Court]
New You forgot:
caseof/case, each of which adds a complexity count. So if I have a case construct for handling the digit keys on a keypad, for example:

\nswitch (keystroke)\n{\n    case 0:\n    case 1:\n    case 2:\n    case 3:\n    case 4:\n    case 5:\n    case 6:\n    case 7:\n    case 8:\n    case 9:\n        do_something_trivial(keystroke);\n        break;\n\n    default:\n        do_something else(keystroke);\n}\n


In this section alone, you have a complexity of 11, which by the "rule of thumb" is too complex and must be simplified. Oh well, the best laid plans....
jb4
shrub\ufffdbish (Am., from shrub + rubbish, after the derisive name for America's 43 president; 2003) n. 1. a form of nonsensical political doubletalk wherein the speaker attempts to defend the indefensible by lying, obfuscation, or otherwise misstating the facts; GIBBERISH. 2. any of a collection of utterances from America's putative 43rd president. cf. BULLSHIT

New Rules of thumb are rules of thumb
And will always break down somewhere.

But in this case I think that that code sample is clearer when written as:
\nif (keystroke < 10)\n    do_something_trivial(keystroke);\nelse\n    do_something else(keystroke);\n

Conversely if your list was a list of, say, random item IDs that got special treatment, then that case statement, written that way, would indeed be a complex thing. I'd strongly prefer to have you give me some context about what the commonality between the items is. If need be by hiding the list in a function with a descriptive name like gets_ira_tax_break_1234(item).

Cheers,
Ben
To deny the indirect purchaser, who in this case is the ultimate purchaser, the right to seek relief from unlawful conduct, would essentially remove the word consumer from the Consumer Protection Act
- [link|http://www.techworld.com/opsys/news/index.cfm?NewsID=1246&Page=1&pagePos=20|Nebraska Supreme Court]
     VB - NO CONTINUE STATEMENT!! ARRGG!!! - (broomberg) - (38)
         Basic was invented that way - (ChrisR) - (16)
             Has had "continue" for many years - (broomberg) - (15)
                 In VB 6 you have - (lincoln) - (1)
                     Exit loop is there - (broomberg)
                 Or you COULD... - (jb4) - (12)
                     In other words, give a "break"! :) -NT - (a6l6e6x)
                     No way! - (broomberg) - (10)
                         Yet Another Way To Do It - (ben_tilly)
                         Warning! Possible religious war pending - (jb4) - (8)
                             Nah, this is more important - (broomberg) - (7)
                                 Some older languages had those constructs - (jb4) - (6)
                                     That doesn't need to be addressed - (ben_tilly) - (5)
                                         If I didn't know better ... - (drewk) - (3)
                                             Good thing that you know better then :-) - (ben_tilly) - (2)
                                                 You forgot: - (jb4) - (1)
                                                     Rules of thumb are rules of thumb - (ben_tilly)
                                         That'd be the Cyclomatic Complexity - (jb4)
         Answer: - (FuManChu) - (17)
             VB is not a Programming Language, it's a Product. -NT - (ChrisR) - (16)
                 So if I WAS to fight, again, what are my alternatives? - (broomberg) - (15)
                     Rython ror Rerl ror Reecee-ell ror a rombo of rall rhree ; - (folkert) - (7)
                         TCL - Never!!!! - (broomberg) - (6)
                             Careful what you ask for... - (folkert) - (2)
                                 I see you ignored the previous. Barry - (folkert) - (1)
                                     Who says? - (broomberg)
                             Come on, TCL and BASIC are as far apart - (Arkadiy) - (2)
                                 Lisp is not procedural?? - (ben_tilly) - (1)
                                     Parenthetically speaking that is. :) -NT - (a6l6e6x)
                     C# is a better match - (ChrisR)
                     ObCRC: Delphi - (Another Scott) - (2)
                         I just pitched C# - (broomberg) - (1)
                             You just described all of MS' programming languages. - (static)
                     Python wins on several of those axes - (FuManChu)
                     Sounds exactly like... - (jb4) - (1)
                         Oh, what's the use?! "Nobody is as blind...", and so on. :-( -NT - (CRConrad)
         Side effect - (JayMehaffey)
         FWIW, VB.Net 2005 will have it -NT - (altmann) - (1)
             ObLRPD: It'll be in the next release.... -NT - (jb4)

And then they ran out of time.
120 ms