C / C++ packages to understand code for refactoring
Asked Answered
L

6

21

I am about to starting to work on a project which involves refactoring and modifying existing code which is in 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
    Generate UML class diagrams from existing code base

  2. UMLStudio
    Creating an object model for your OO legacy code is the best approach to analysing, understanding and maintaining it. UMLStudio can automatically convert C++, Java, CORBA IDL, PHP 5, and Ada 95 code into OOA&D notation faster than any other CASE tool.

  3. CodeDrawer for C++
    The CodeDrawer converts source code to visual based diagrams. 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

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

  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.

  7. Java Reverse Engineering Tool Generates class diagrams and relations between classes from Java source code.

  8. Source Insight Great source browsing software

One more, Thanks to Steve Townsend
Klocwork

Lorettelorgnette answered 23/9, 2010 at 9:34 Comment(5)
You ask for open source tools and then list several that are not.Mutation
@Ira Baxter - True, I couldn't find much of open source tools :( I am trying to get hold of those, will try to post soon. Please feel welcome to add up if you know any.Lorettelorgnette
@Als: One non-open-source choice is Understand for C and C++: www.scitools.com. (I have not used this tool).Mutation
Understand seems good, I just tried trial version.Unpeopled
@Als:CppDepend can also help you to understand a large C++ projects, and trial version could be sufficient for your needsKilligrew
P
10

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.

Plenipotentiary answered 23/9, 2010 at 9:49 Comment(6)
I do understand such a code cant be refactored just by itself, needs understanding, i know that is a problem and I am asking help to overcome.Also, as for the wonderland living I am hoping if theres some tool which can refactor certain small modular sections of the code.Lorettelorgnette
I said you're living in wonderland to point that refactoring is a human intelligence process that can only be done with the role of each part of code in mind, that is impossible to do by a software. Or maybe you just want a renaming or code reformating tool?Plenipotentiary
ofcourse human intelligence is needed to refactor a source code, its a developed code afterall, but i am looking for tools which would make it easier to work with a voluminous code base.Any tool suggestions for that?Lorettelorgnette
If you use Visual Studio, I can only recommand Visual Assist to help on the renaming/applying macros.Plenipotentiary
In principle it is possible for software to exist that refactors code well. In fact, many common refactoring chores are logically simple and ought to be easy to automate. But as far as I know, no such tool does exist.Cameroun
@Cameroun Indeed, and actually, there are recent development related to LLVM that shows that such refactoring tools can indeed be developed.Plenipotentiary
I
4

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

Ideate answered 23/9, 2010 at 11:21 Comment(5)
Thanks for pointing out the testing point. Really important one.I missed to mention out Yes the testing framework exists and its a functional one. And we do have to prove the new softwares worth by providing test results after the refactoring/modifications. Ofcoure nothing like running the code and inspecting it as you mentioned and we would be looking up for that.But are there any tools that will help reverse engg code to say design charts to develop overal understanding? design docs are virtually non existent :( We are not looking to skip the code inspection and understanding by debugging.Lorettelorgnette
@Als - what is your platform, IDE and compiler?Ideate
@Steve Basically, it is a custom http and wap software stack for mobile devices. It has a good platform abstraction layer which ensures it can be ported to various mobile platforms. Currently, we have a working version for windows simulator using win32 api and using Microsoft visual studio. We will port it further on for other platforms like Brew etc.Lorettelorgnette
It seemed like a lot of it was questioning the OP premises and only the last sentence was anything that the OP could actually use. Sorry about not commenting straight up, I was just checking an answer from a question I just asked.Parisparish
@Steve Townsend - Thanks! I did some google search and came up with a few good tools, will post them in as Edit just in case to help someone sailing in same boat as me :)Lorettelorgnette
M
2
  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.
Membranous answered 23/9, 2010 at 9:54 Comment(2)
But to generate a doxygen doccument you do need to add comments using specific formatting right?Lorettelorgnette
You can extract everything even if it's not documented. It will give you a first outline. Then you can add comments so the documentation will improve over time. That's IMHO a good way to 'learn a project', and it will greatly improve code 'quality', measured in comments/code ratio.Membranous
M
2

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.

Mutation answered 4/10, 2010 at 15:38 Comment(0)
L
1

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.

Lenrow answered 1/2, 2011 at 21:34 Comment(0)
E
0

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.

Etherege answered 8/3, 2013 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.