– What is static program analysis ?
Static program analysis allows the gathering of informations about the execution behaviour of your code without actually executing it. It is the opposite of dynamic program analysis (like debugging) which required the code to be executed.
– Ok! But why should I use this in practice ?
- To save time by suppressing the save/execute cycles induced by syntax errors (missing “;”, function or variable not initialized, typos, …). Correcting these errors at the debugging step (dynamic analysis) requires that you write, save, (re)compile or (re)execute your program multiple times.
- To gain in performance by identifying libraries/variables/functions that are not initialized properly or not use at all. A must, for self-taught programmers or for those who do not have a lot of coding experience.
- To gain in readability by following some well established stylistic rules developed by a group of programmers. These rules are a standard to adopt. Quite helpful to learn a new language!
– Ok, I’m interested, how does it work?
It depends on your programming preferences. Do you write your code in a text editor or in an integrated development environment (IDE)?
Static analysis tools are already integrated in most of the IDE. Or language specific plugins are available for you to install (for example, PyDev for python in Eclipse). Those tools will directly highlight hence identified errors in your code (it works like a spell-checker).
For those of you who prefer simpler text editor (like me!), small programs (namely lint or linter) can be added to your favorite editor
(emacs, vim, sublime text, …). Here, your errors are also highlighted in your code. A quick look at your program is all is needed to spot them and correct them quickly.