Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!necntc!linus!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: comp.software-eng Subject: Re: examples complexity measure usage Message-ID: <2656@mmintl.UUCP> Date: 13 Jan 88 23:52:36 GMT References: <398e2f3e.fed5@apollo.uucp> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT. Lines: 55 In article <398e2f3e.fed5@apollo.uucp> marc@apollo.uucp (Marc Gibian) writes: |As promised, here are some examples of decreasing the quality of code |while reducing the complexity measure value. ... The contractual |requirement was that every procedure and function have a McCabe value less |than or equal to 10. One general comment: these examples suggest that, at least at the current level of development, the complexity measures are better as a tool for evaluating code than as a goal. They make a better servant than a master. |original fragment: | | if (a == value1) then | y = target1; |[...] | else if (f == value6) then | y = target6; | end if; | |transformed fragment: | | new_func((a == value1), target1); |[...] | new_func((f == value6), target6); | |with new_func defined as: | |new_func(relation_value, target) |{ | if (relation_value) then | y = target; | end if; |} Two comments here: It seems to me that a metric should regard an "if ... else if ... ... [else ...]" construct as approximately equivalent in complexity to an "if ... else ..." construct. It seems to me also that use of global variables should be penalized. As a first approximation, one might include a cost of 1 for each global variable referenced by the program. (This still leaves the option of putting several more or less irrelevant globals into a structure, to cut down on the number of globals. Perhaps each component explicitly referenced should cost 1?) |I agree with the goal of using a metric to measure the characteristics of |code, I simply believe that no metric now exists that truly measures the |qualities that people (management, customers) want to measure. This seems like a reasonable summary. -- Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108