Visualising Code Structure in Large Projects?
TheMaccLads asks: "I've recently joined a new C++ project, and it's in a terrible state. There are 100-odd source directories, dozens of libraries, and a couple of dozen executables and DLLs. Some executables pull in (i.e. compile themselves) the occasional source file from a library, instead of using the libraries. My job is to port a subset to unix, but I need a tool to visualise all the relationships between directories, projects, libraries, and so on, because my brain will overheat soon otherwise. Preferably a tool that will do it by parsing the MS Dev studio projects and workspaces, but if I have to write it myself in Perl, I will! Anyone know of any tools? Or suggest an approach?"
Really! Just start drawing lines and boxes as you delve through manually. If you get something to do it automatically, you still won't have a good visualisation in your head.
Theres other products out there too, All are expensive.
I have used this, it is fantastic; it will work with your old C++ code straightoff, & also accepts javadoc-style comments. Handles the worst code elegantly. Draws pretty graphs for you. Does the bits of a programmer's job that really ought to be automated.
McCabe & Associates makes some software that will automatically create a graph for visualizing a large software project, even one using mixed languages. Their marketing department renames the software every other week, but that's what they do. Arthur Watson (PhD, Computer Science, Princeton) did their most interesting research a few years ago, but has since left the company.
Their software will also help re-engineering and testing efforts: it'll tell you how complex your code is (and thus what parts of it are most likely to break), and it'll instrument your source code and show you what logic paths you've hit in your program during testing, and what code remains untested. It used to be pretty solid stuff (and pretty pricey!); I'd love to see some free/open software that does stuff like this.
Disclaimer: I'm a former intern.
It is the best editor I have seen yet (multiple language support, totally configurable, excellent tech support), and it is great for navigating large projects. It parses all of the files in your project as text (so you can browse code that does not compile), and is a good complement to Dev Studio's build-based browsing.
It integrates with Dev Studio, so the two editors and environments will update each other when you switch between them.
I probably shouldn't admit this on /., but at one job, I had a Windows box dedicated to running CodeWright, editing QNX code over Samba. It was actually worth the extra box. At another job, I was using it to edit files for Sun and DEC UNIX (no Samba this time), and it was still worth it to ftp the files back and forth, rather than use what I could find in the UNIX world at the time.
I know also that there is some really good code mapping software out there, but I can't give you any names off of the top of my head. Large sheets of paper really do the trick, though. I have seen people spend a lot of time with visio getting very little done, but I haven't used it myself, so don't listen to me and I'll shut up now.
Why is Grand Theft Auto a much more serious crime than Reckless Driving?
A few years ago, I found myself at a similar situation; I had to port a Bridge game from DOS to Mac. I had the full source code, but it was so old I couldn't make it compile. Even worse, I had never played Bridge!
.BAT files, the 'Find' command from DOS, and QBasic. Those utilities allowed me to type any function or global variable (there were lots of globals!!) and it would tell me in what file was defined, declared, and what functions used it (with a tree of callers)
I started playing with the executable, and learned the cards game (very boring! never played it again).
Then I wrote some utilites using
It took me a couple of days to write the utilities, and proved really lifesaving
after that, I used paper. If there was a long function with lots of nested loops and goto's (it was C, but looked like bad basic); I would print it and tape the paper to the wall. Then just spend hours looking at it, pencil at hand, drawing arrows and notes over the code
Very slowly, I separated the engine from the UI and IO code.
Then I just wrote a new application on the mac, that called the old engine code. Of course the game gained a lot of mouse manipulability, sound effects and even a video intro (without QuickTime, of course)
In short, first craft your tools, then use them. Spend lots of time just looking at the code. Slowly the hate will melt into pity for it, then your job will be to liberate it!
-Kz-
I remember seeing some other solution somewhere that might be applicable. Can't remember what it was called. No wait, I'm thinking of a Thai cookbook. Never mind.
Unless I overlooked something, the only diagrams Doxygen draws are class hierarchies. Unless you have a lot of classes, I can't see bothering with a whole big app just for that.
Doxygen sounds like it's handy for generating API docs with a minimum of effort, but pretty useless for analyzing mysterious legacy code.
5 People
3 Afternoons
1 Huge Pile of Code
2 Large White-boards
3 small little cubes of those MultiColored post-ITs
2 Handfuls of assorted colors DryErase markers
Start by pouring all the ingredents into a medium sized classroom-type-room with lots of chairs and a small assortment of refreshments. (Be sure to wash off the white board.) Tell all the people what you are trying to do and tell them they will have to help you out for at least one afternoon over the next couple of days. [Whatever. Intimate time with code. They'll learn something. You'll get to talk to eachother.] Tell some they have to stay, others they'll have to help you tomorrow, etc. Look over the code and decide which portion you'd like to work with today. Isn't it pretty? Now - by applying the markers and the PostITs to the White-board, carefully extract the useful parts of the code, leaving the nasty, hairy choke behind. Go for the structure. Go for the connections. Dispose what is leftover. Take a high resolution picture. Go home and get some sleep.
Repeat the above for each piece of the program you'd like to work on for each particular day. After you have extracted all the good, and none of the bad, combine the extract with your wonderful programming skills, the sarcastic cheers from your friends in nearby cubicles, and big high-resolution printouts of your photography work in a CPU Unit Processor, blending until firm. Chill, Serve and Enjoy!
...is something like etags, but which will show who calls the function/method I'm looking at now. Etags in vim is great for tunneling down to the definition of the functions that I'm calling, but not so good for going "up". So far I mostly end up using "find . -type f -name \*.[Chc] -print0 | xargs -0 grep foo", which is time consuming and annoying.
The next Cmdr Taco duplicate will be ready soon, but subscribers can beat the rush and see it early!
If you really need to understand the code, you will just have to spend the time. Diagrams and tools may help a little, but ultimately, there are only so many bits you can get into your head per hour.
You say "DLLs" so I'm guessing PC rather than Linux... Source Dynamics produce Source Insight which is a groovy C++ editor that scans all your code, holds it all in a metabase, and while you're perusing it runs a lazy thread in a seperate window to show you more details of whatever is under the cursor. It's not a C++ visualisation tools (it has a speedbar outline of the current file) but is very good at helping you jump navigate thru large amounts of source code.
The bonus is that it runs very fast, is useful as an editor, and knows enough about all your code to do smart things like smart-gloabl-rename, find all references to symbols, etc.
They do a 30 day free eval too...
T
I spent a lot of money on booze, birds and fast cars. The rest I just squandered. - George Best