开发者

Is there any tool that can analyze the dependencies between variables in c# programs?

There are many tools that we can use to show the dependencies between modules, source code files, classes, or functions etc. But there seems no tool for analyzing the dependencies between variables. Given a dependency graph of variables would be helpful for understanding and refactoring the code.

For example, if variable b is only used for calculating the value of variable c as follows:

b = a;
....
c = b + 2;

Maybe we could remove variable b to make the code more readable:

....
c = a + 2;

This kind of refactory may be hard if the code is very complex or has many bad smells.

Is there any tool that can 开发者_运维知识库analyze the dependencies between variables in c# or other programming languages?


The Phoenix Project at Microsoft Research has enabled some pretty interesting tools. One demo I've seen shows highlighting of data-dependencies. So you could hover over 'c' in your example, and all expressions that contribute to that calculation would be highlighed. It was more a demo of phoenix, than a fully fledged developer tool, but very cool to see that it could be done. Phoenix is a free download, so you can see what kind of sample apps are included.


Resharper is a good tool to analyze c# code. At least it will show you unused variable and variable that you assign value but never used.

If you considering serious refactoring of your code, you could write unit test to be more sure that you do not break something.


See discussion on how the DMS Software Reengineering Toolkit does (control and) data flow analysis. This is essentially classic compiler analysis of information flows, which includes what are called def-use chains. The use-chains show how a value (a specific assignment) is consumed by other parts of the program.

These information flows are computed as data structures, and so they are directly easy to see. (The web page does show pictures but they are dumped graph results fed to dot. To make this into a tool is more effort.

We have built program slicers with this, that display this information in a UI. They aren't commercially available yet.

Grammatech makes such program slicers for C and Ada, I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜