简体   繁体   English

用C / C ++包来理解重构的代码

[英]C / C++ packages to understand code for refactoring

I am about to starting to work on a project which involves refactoring and modifying existing code which is in c & c++. 我即将开始研究一个涉及重构和修改c&c ++中现有代码的项目。 The code is a bloated one and is in huge volume. 代码是一个膨胀的代码,并且数量巨大。 Of course since the code needs to be modified, an understanding of the code has to be developed and in a very short span of time since we have some pretty time pressed project schedule. 当然,由于代码需要修改,因此我们必须在非常短的时间内开发对代码的理解,因为我们有一些非常紧迫的项目进度表。 Can anyone please suggest any open source tools which will help in achieving the above. 任何人都可以建议任何有助于实现上述目标的开源工具。 In short what I am looking for is tool which can: 总之,我正在寻找的工具可以:

  1. Reverse engineering tools which will help understand the design. 逆向工程工具,有助于理解设计。
  2. Sequence generator tools which will help draw sequences at run time(Most probably we will be able to run the code, but not in the initial stages at least) or through code examination. 序列生成器工具将帮助在运行时绘制序列(最有可能我们将能够运行代码,但至少不能在初始阶段)或通过代码检查。
  3. Good code browsing tools to study the existing code base. 良好的代码浏览工具,可以研究现有的代码库。
  4. Suitable tool which can auto refactor code with minimal efforts. 适合的工具,可以轻松自动重构代码。

Please do tell me about any experiences,preferences or favorites worth looking out for. 请告诉我任何值得关注的经历,偏好或收藏。

[EDIT] Came up with a list of tools to help in above. [编辑]想出了上面提供帮助的工具列表。 Here's the list: 这是清单:

  1. Graphviz & doxygen Graphvizdoxygen
    Generate UML class diagrams from existing code base 从现有代码库生成UML类图

  2. UMLStudio UMLStudio
    Creating an object model for your OO legacy code is the best approach to analysing, understanding and maintaining it. 为OO遗留代码创建对象模型是分析,理解和维护它的最佳方法。 UMLStudio can automatically convert C++, Java, CORBA IDL, PHP 5, and Ada 95 code into OOA&D notation faster than any other CASE tool. UMLStudio可以比任何其他CASE工具更快地将C ++,Java,CORBA IDL,PHP 5和Ada 95代码转换为OOA和D表示法。

  3. CodeDrawer for C++ CodeDrawer for C ++
    The CodeDrawer converts source code to visual based diagrams. CodeDrawer将源代码转换为基于可视化的图表。 Class, struct, and any elements of source code can be shown diagrams. 可以显示类,结构和源代码的任何元素。 It also shows the logics of a function and a method. 它还显示了函数和方法的逻辑。 The CodeDrawer helps understand source code of your project CodeDrawer有助于理解项目的源代码

  4. Imagix Imagix综合
    Reverse engineering and visualization of source code lead to improved program comprehension. 反向工程和源代码可视化可以提高程序的理解能力。 Speeds: Learning Unfamiliar Code Change Impact Analysis Integrating Open Source Code Code Reuse Software Maintenance 速度:学习不熟悉的代码更改影响分析集成开源代码重用软件维护

  5. AgileJ AgileJ StructureViews is a plug-in for the Eclipse Java IDE which generates highly customisable UML class diagrams on an industrial scale, ideal for agile development or exploration of any existing Java codebase. AgileJ AgileJ StructureViews是Eclipse Java IDE的一个插件,它可以在工业规模上生成高度可定制的UML类图,非常适合敏捷开发或探索任何现有的Java代码库。

  6. MaintainJ If you can run the code base then MaintainJ generates UML sequence and class diagrams at runtime when you run a particular use case. MaintainJ如果您可以运行代码库,那么当您运行特定用例时,MaintainJ会在运行时生成UML序列和类图。

  7. Java Reverse Engineering Tool Generates class diagrams and relations between classes from Java source code. Java逆向工程工具从Java源代码生成类之间的类图和关系。

  8. Source Insight Great source browsing software Source Insight很棒的源码浏览软件

One more, Thanks to Steve Townsend 还有一个,感谢Steve Townsend
Klocwork Klocwork的

The code is a bloated one and is in huge volume. 代码是一个膨胀的代码,并且数量巨大。 Ofcourse since the code needs to be modified an understanding of the code has to be developed and in a very short span of time since we have some pretty time pressed project schedule. 当然,由于需要修改代码,因此我们必须在非常短的时间内开发对代码的理解,因为我们有一些非常紧迫的项目进度表。

Then you have a management problem : if you already know you have little time to UNDERSTAND a lot of code, you're doomed. 然后你就遇到了一个管理问题:如果你已经知道你几乎没有时间理解很多代码,那你就注定要失败了。 To understand this code, you'll have to make it run and go through it and it will take time. 要理解这段代码,你必须让它运行并通过它,这需要时间。 Tools will just give you a big map of things but will not show you the real path. 工具只会给你一个大的地图,但不会向你展示真正的路径。

Suitable tool which can auto refactor code with minimal efforts. 适合的工具,可以轻松自动重构代码。

You're living in wonderland. 你生活在仙境里。

There are tools that gives you the structural architecture of you application, but that will not really help without going through each module one by one and read the code. 有些工具可以为您提供应用程序的结构体系结构,但如果不逐个浏览每个模块并阅读代码,这将无济于事。 First the code that use the modules, then the code inside the modules. 首先是使用模块的代码,然后是模块内部的代码。

The fact that it's C and C++ makes it even harder to define the time that it will take you as it's also relative to the knowledge you have of those languages and the level of knowledge of the people who wrote the app. 事实上它是C和C ++使得定义它将花费你的时间变得更加困难,因为它也与你对​​这些语言的知识以及编写应用程序的人的知识水平有关。

The first question you should ask is 'how do I make sure any changes we make do not break the system?'. 您应该问的第一个问题是“我如何确保我们所做的任何更改都不会破坏系统?”。 Yet your question does not mention tests at all. 但你的问题根本没有提到测试。 That's a red flag to me. 那对我来说是个红旗。

I agree with others that tools are not the solution (not likely to turn up in the form you want, not likely to be 100% trustworthy on their own). 我同意其他人的看法,工具不是解决方案(不太可能以你想要的形式出现,也不可能100%自信)。

Your goal should be to quickly identify the area(s) to be changed - I would do this via inspection and running the code (preferably in existing tests - do you have them?), and make sure you have comprehensive unit and system test coverage on them before you touch a single line. 您的目标应该是快速确定要更改的区域 - 我会通过检查和运行代码来执行此操作(最好是在现有测试中 - 您有吗?),并确保您拥有全面的单元和系统测试覆盖率在你触摸一条线之前。 Without that base, you are going to be flying blind and deadlines are way more at risk. 如果没有这个基础,你将会失明,最后期限会更加危险。

At the very least, if you don't have good tests, communicate this concern to your line upfront so that if things go pear-shaped you are seen to have raised the issue. 至少,如果你没有进行好的测试,请将这个问题提前告知你的线路,这样如果事情变成梨形,你会发现问题已经提出。

You could look at something like this - not used myself though: Klokwork Architect 你可以看看这样的事情 - 虽然没有用过我自己: Klokwork Architect

There are very few tools that can parse and transform C and C++ code. 很少有工具可以解析和转换C和C ++代码。 As a first step, parsing of these languages is considered hard all by itself. 作为第一步,解析这些语言本身就很难。 Another key problem is the preprocessor, which is used pretty abusively (eg, not in a structured way) in C programs and makes it difficult for a parser to see the program structure, and consequently difficult for an analyzer (needed to decide when refactorings are legal) to do its analysis correctly. 另一个关键问题是预处理器,它在C程序中非常滥用(例如,不是以结构化方式)并且使得解析器难以看到程序结构,因此分析器很难(需要决定何时重构)合法)正确地进行分析。

Modulo these glitches, our DMS Software Reengineering Toolkit can be configured to carry out refactorings on C and C++ code. 通过模拟这些故障,我们的DMS软件重新设计工具包可以配置为对C和C ++代码进行重构。 DMS has industrial strength parsers for C and C++ and uniquely can capture most preprocessor uses as part of the internal code structures (typically people trying to parse C/C++ expand the preprocessor directives away, and that isn't an option for refactoring). DMS具有用于C和C ++的工业强度解析器,并且可以捕获大多数预处理器用作内部代码结构的一部分(通常人们试图解析C / C ++会扩展预处理器指令,而这不是重构的选项)。

We've used it to carry out massive code reorganizations on C++ code (where preprocessor abuse is minimal because C++ has a variety of other ways to configure code). 我们已经用它来对C ++代码进行大规模的代码重组(其中预处理程序滥用很少,因为C ++有许多其他配置代码的方法)。 We also done some automated reengineering of C systems, but with somewhat more effort to handle the abusive preprocessor uses. 我们还对C系统进行了一些自动化重新设计,但需要更多的努力来处理滥用的预处理器用途。

What it is not is interactive . 它不是互动的 You have to plan the refactoring transformations and specify them with a pattern matching language. 您必须规划重构转换并使用模式匹配语言指定它们。 But it is reliable. 但它很可靠。

  1. If you have the source, technically it's not reverse engineering. 如果您有源,从技术上讲,它不是逆向工程。 You can use the very good Doxygen to generate documentation (including diagrams - install GraphViz too!) : link 你可以使用非常好的Doxygen来生成文档(包括图表 - 也可以安装GraphViz!): link
  2. No idea, not sure it exists. 不知道,不确定它是否存在。
  3. Your web browser, along with Doxygen, if you enable source code browsing. 如果启用源代码浏览,您的Web浏览器以及Doxygen。 Visual Studio, with right click for jumping to definitions, and the debugger to step through the code and gain an understanding of its working (use and abuse the Step Out command). Visual Studio,右键单击跳转到定义,调试器逐步执行代码并了解其工作(使用和滥用Step Out命令)。
  4. There are tools to do refactoring, but minimal effort and 'auto refactor' are very very hard to achieve, I don't think you find tools for that. 有一些工具可以进行重构,但是最小的努力和“自动重构”非常难以实现,我认为你找不到相应的工具。

我只是想在研究/重构未知代码库时特别是在使用Emacs / CEDET这样的工具时添加注释, CTAGS / ECTAGS非常有用。

5 agilej ( http://www.agilej.com/ ) AgileJ StructureViews is a plug-in for the Eclipse Java IDE which generates highly customisable UML class diagrams on an industrial scale, ideal for agile development or exploration of any existing Java codebase. 5 agilej( http://www.agilej.com/ )AgileJ StructureViews是Eclipse Java IDE的插件,可以在工业规模上生成高度可定制的UML类图,非常适合敏捷开发或探索任何现有的Java代码库。

AgileJ applies to your points 1 (reverse engineering to help understand the design) and 3 (Good code browsing tools to study the existing code base). AgileJ适用于您的要点1(逆向工程以帮助理解设计)和3(用于研究现有代码库的良好代码浏览工具)。 Bloated code that has been rapidly slapped together generally shows up as things like: 已迅速打包的膨胀代码通常显示如下:

  • One or two large classes which act as the dumping ground for each bit of last minute functionality (the blob anti pattern) 一个或两个大类,作为最后一分钟功能的每个位的倾倒场(blob反模式)
  • Cut and paste code where a whole class has been copied and tweaked for a new purpose rather than factoring out the common parts to a base class first 剪切和粘贴代码,其中整个类被复制和调整以用于新目的,而不是首先将公共部分分解为基类
  • Lack of OO as evidenced by many classes with only get and set methods 许多类只使用get和set方法证明缺少OO
  • Dependencies are matted, everything depends on everything else throughout the project and there is no layering within the architecture 依赖关系很重要,一切都取决于整个项目中的其他所有内容,并且架构中没有分层

There are plenty more traits which can be added to this list but the above are made more obvious on a class diagram. 有更多的特征可以添加到这个列表中,但上面的内容在类图上更明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM