C / C++ packages to understand code for refactoring

依然范特西╮ 提交于 2019-11-29 20:29:56

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.

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).

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

There are very few tools that can parse and transform C and C++ code. 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 (e.g., 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.

Modulo these glitches, our DMS Software Reengineering Toolkit can be configured to carry out refactorings on C and C++ code. 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).

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). We also done some automated reengineering of C systems, but with somewhat more effort to handle the abusive preprocessor uses.

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.

I just thought I'd add a note that CTAGS/ECTAGS is very useful when studying/refactoring an unknown codebase, especially when using a tool like Emacs/CEDET.

jv42
  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
  2. No idea, not sure it exists.
  3. Your web browser, along with Doxygen, if you enable source code browsing. 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).
  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.

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.

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). 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)
  • 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
  • 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!