This question already has an answer here:
- How to visualize code? [closed] 18 answers
Sometimes when code is too complex, I break it down into parts.
Is there another kind of technique/visualisation to help have a more clear picture of the code?
Bits and pieces from comments: Why is this tool so good? What's not so good about it?
I don't know what to say really. I've been using it for, well, quite some time now (years) and it is really a tremendeously useful tool when analyzing large projects. It has replaced my IDE in a way. I don't rely on graphs that much; more on the mechanisms of restructuring and manipulating variables and such. Check their page.
Within a complete project I find class diagrams most useful, with a machine-generated diagram handy if an existing project doesn't have documentation. There's a range of tools for generating class diagrams automatically, and generally they work fine for small projects. I like to split bigger projects out, either into layers or class groups, but this requires a certain minimum level of class coherence to be useful.
Within a single file two things for Visual Studio that I find handy are ctrl-wheel to zoom the code right out and the Code Map plugin from AX Tools. Both are quite good for getting a feel the structure of the file.
In my experience there are two quite different times when you want to do this. When you're designing software diagrams help you plan the structure and fit it to your requirements. For this almost any tool will do, because it doesn't need to be very interactive with the code, when the code eventually arrives. The other case, of course, is when you get a giant mess dumped in your lap and want to understand it. For that the quality of the reverse-engineering is key, and unfortunately I can't reccommend any specific tools. I find they all struggle once you get into hundreds of classes with high coupling and low cohesion.
In Visual Studio you can generate a class diagram from your code that is fairly helpful for getting an overview of classes, their contents, and their relationships. The best part is that it is a "live" and editable diagram, in that you can edit the diagram and the changes effect your code.
Much like some of the others. You should look into learning UML There are some good tools out there that will auto generate these diagrams from your existing code, but I have found it very helpful to create these diagrams up front before I start a project and modify them as I go along.
Maybe is not what tool you use to visualize code, but how do you organize / split it.
Today there is a lot of applications done in Functional Programming and Object Oriented Programming, but, they are so messed up, something I call "Spaghetti Object Oriented Code".
Are your loops ("for", "foreach", "while") sentences or alternation ("if" / "switch" / "case") sentences too long (more than 6 lines) ? Perhaps, you should move that code into a new function / method.
Are you organizing your code in namespaces / modules / packages ?
Are your classes code too long ? maybe you should break a single class into a "grandparent" class, a "parent class", and a "child" class.
Classes usually have 4 groups of methods, initialization (constructor and helper methods), execution (methods you use when object is instantiated, and helper methods), finalization (destructor and helper methods), plus "accesors", methods to access properties.
Does your classes methods, are well defined, in which group belongs ?
If your code is messed up, your visualization, charts, flowcharts, U.M.L., whatever, will look messed up, also.
U.M.L. may help you organize your code. You don't need a U.M.L. application, for your scenario, a whiteboard and some markers will help you.
But, if you do diagrams of your code, you must think in reversing the process, modying the diagrams, and later, modifying your code upon the changes you do to your diagrams...
I guess my more simplistic, yet old-school approach is to write the code in pseudo-code.
Basically I create a new text file, and just write down via comments and/or pseudo-code the basic logic flow of the code I need to create.
I try to identify what sections are reusable or need to be executed or copied many times, and then convert those into the reusable format for my language, cfc's, custom tags, cfscript's etc. I am sure each of us has our own methods for our own languages.
I also try to identify huge chunks of sql code that can and should be moved to views and stored procedures...
I have been out of practice in doing this in the last year.
But it really helps in coding, if I pre-plan the code, to make sure I have a clear idea of what functional needs I am meeting or changing.
It get's especially hard when 99% of the time I am modifying someone else's code, and I don't always understand it. So it becomes a struggle to leave that code as is, to not interfere with it's functionality, while adding/changing functionality that is my assignment.
There is no 1 answer, just we all need to get better and more practice at planning our code.
I have a very large java code composed by multiple projects. The code is so big that a human brain can not handle it :-) The trick I do is to reverse engineer my code into an UML model and then create graphical views from my code using the UML model. Really powerful and amazing technology. My model can handle all my projects into a single UML model and I can describe project interactions directly at UML level of abstraction. I can also select to visualize only the relevant information. The graphical quality is so good that huge packages, composed by hundred of classes can be visualized inside a single class diagram !!