As the name suggests it is a technique to analyze a software without actually trying to run it. It obviously implies that the technique looks at the source code of the said software. Note that it is not Software Testing - wherein we actually compile and run the software application. The application is fed with test data. Software Testing is a part of Dynamic Analysis. Typically static analysis tools are built on top of compiler front-ends. The information collected by compiler front-ends is run through sets of rules to find pre-defined patterns or stored for further analysis.
So is analyzing source code without actually running the software of any use? It turns out that it is very useful - both for prevention of bugs and also for discovery of information. Primarily Static Code Analysis tools have been used for two purposes:
- Making code more maintainable: Over time the software community has collected lot of good coding practices. It is possible for a tool analyze source code to find if any such practices are violated. More importantly these kinds of tools can now be integrated into Integrated Development Environments (IDEs) so that a software developer can be warned right at the moment s/he is committing a mistake. These tools can also be run on software that is already existing to point out such weak areas or outright defects. Typically these kinds of issues were expected to be caught in Peer Reviews, but its always a good idea to take help from a software.
Another way to make software more maintainable by using these tools is to rearrange the code (Beautify, Re-factor) so that it is well-formatted and adheres to good design practices. The resulting rearranged code is more elegant, more logical and hence more maintainable.
Analyzing software for other non-functional characteristics like Security, Performance, Scalability are studied but are not as common place.
- Finding design information in existing code: More often than not, software is written under artificially created "Time to Market" pressure. Another very misused term is "We use agile coding methodologies". Whatever be the means, but the end result is large amount of poorly documented and poorly structured source code. Further it is very likely that the team that inherits this source code is not the same as that which writes it. At these times tools that can extract design information from source code become very critical to the success of the projects.
These are called as Information Abstraction systems. They collect data from the source code and put it into data stores (like relational databases). Querries can then be built on these data stores to aid in discovering design information. For example querries like - what are all the recursive functions in this software? Which classes 'use' a given class and so on. This process is also called as Reverse Engineering. There are tools that can generate 'intelligent' class diagrams from source code. Many a times such tools save the day for software developers.
Another utility of the information thus collected is to aid a software developer to navigate large code bases easily - one who has waded through millions lines of code appreciates their value.
References:
This is definitely not exhaustive, but I wanted to put together some interesting aspects of static analysis.
- Wikipedia (http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis) the link says it all.
- The C Information Abstraction System (http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=48940) is an example of an Abstraction System I mentioned above.
- The Wisconsin Madison Program Slicing project (http://www.cs.wisc.edu/wpis/htmlw/) is an excellent example of the varied kinds of analysis that can be done on information extracted from a software. It has some very interesting possibilities.
- In this story Aron Campbell (http://asert.arbornetworks.com/2006/10/static-code-analysis-using-google-code-search/) uses static analysis for providing some very interesting insights into source code - a very enlightening (and amusing) discussion.
No comments:
Post a Comment