您维护的任何功能中最高的环复杂性是什么?您将如何进行重构?

编程入门 行业动态 更新时间:2024-10-24 07:23:44
本文介绍了您维护的任何功能中最高的环复杂性是什么?您将如何进行重构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 NDepend 对我维护的旧系统进行一些探索(出色的工具可以将其检出), 另一天。我的发现几乎使我在屏幕上洒了满口咖啡。

I was doing a little exploring of a legacy system I maintain, with NDepend (great tool check it out), the other day. My findings almost made me spray a mouthful of coffee all over my screen. The top 3 functions in this system ranked by descending cyclomatic complexity are:

  • SomeAspNetGridControl.CreateChildControls(CC为171 !!)
  • >
  • SomeFormControl.AddForm(CC为94)
  • SomeSearchControl.SplitCriteria(CC为85)
  • SomeAspNetGridControl.CreateChildControls (CC of 171!!!)
  • SomeFormControl.AddForm (CC of 94)
  • SomeSearchControl.SplitCriteria (CC of 85)
  • 我的意思是171,哇!!! 低于20 还是不应该?所以这让我感到奇怪。您维护或重构的最复杂的功能是什么?以及如何重构这种方法?

    I mean 171, wow!!! Shouldn't it be below 20 or something? So this made me wonder. What is the most complex function you maintain or have refactored? And how would you go about refactoring such a method?

    注意:我测量的CC是通过代码而不是IL进行的。

    Note: The CC I measured is over the code, not the IL.

    推荐答案

    与几年前我工作的1970年代老式COBOL相比,这是孩子们的东西。我们使用原始的 McCabe 工具以图形方式显示某些代码的CC。打印输出是纯黑色的,因为显示功能路径的线条非常密集且像意大利面条。我没有数字,但它必须比171高得多。

    This is kid stuff compared to some 1970s vintage COBOL I worked on some years ago. We used the original McCabe tool to graphically display the CC for some of the code. The print out was pure black because the lines showing the functional paths were so densely packed and spaghetti-like. I don't have a figure but it had to be way higher than 171.

    每个代码完成(第一版):

    如果分数是:

    • 0-5-例程可能很好
    • 6-10 -开始考虑简化例程的方法
    • 10+-将例程的一部分分解为第二个例程,并从第一个例程中调用它

    在破坏原始例程时编写单元测试可能是一个好主意。

    Might be a good idea to write unit tests as you break up the original routine.

    更多推荐

    您维护的任何功能中最高的环复杂性是什么?您将如何进行重构?

    本文发布于:2023-11-30 15:05:09,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1650438.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:复杂性   您将   重构   功能

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!