PVS-Studio has learned to watch over your programming

285 views

Published on

PVS-Studio now has an operation mode that will help you to find errors and misprints as soon as possible. The analyzer launches right after the files have been compiled and "blushes with shame" for your code if something goes wrong. The feature is currently available only for Visual Studio 2010 users.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
285
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

PVS-Studio has learned to watch over your programming

  1. 1. PVS-Studio has learned to watch over Studioyour programmingAuthor: Andrey KarpovDate: 24.06.2011PVS-Studio now has an operation mode that will help you to find errors and misprints as soon as npossible. The analyzer launches right after the files have been compiled and "blushes with shame" for blushesyour code if something goes wrong. The feature is currently available only for Visual Studio 2010 users users.I wrote many times that the sooner an error is detected, the lower is the price of fixing it. Well Im Well,certainly not the first one to say it and authors of numerous books and articles have been repeating thisover again. Take S. McConnell for example. So I will not repeat myself. McConnell,The previous versions of the PVS PVS-Studio analyzer had to be run manually or during night builds. It issurely fine when you can look through a log at morning and fix some error found But its not ideal. It found.doesnt prevent you from making a couple of small mistakes during the day and spending 10 minutes tofind each of them. PVS-Studio will hardly help you in such a case: its not convenient to run it only for Studio schanged files and its too long to run it for the whole project s project.Fortunately, we are programmers ourselves and we are responsive to needs of our keyboard colleagues.A new mode of incremental analysis has appeared in PVS-Studio 4.30. Verification is now almostcombined with the compilation step: the analyzer checks those files which are being compiled bypressing the F7 key that everyone loves so much. This mode can be enabled not just simply but verysimply: you just have to check the box opposite to the "Incremental Analysis After Build item in the Incremental Build"PVS-Studio menu:Now lets see how it works by an example. Suppose I enjoyed the process of programming very muchand was in a hurry, so I made a mistake in an array index: arrays
  2. 2. The result of this expression is always false. But I do not take notice of it. Im writing the code furtherand feeling happy. Then, satisfied with the work Ive done, I press F7 and the modified file compilessuccessfully and VS2010 does not generate any warnings. I proceed to edit the next code fragment.But when compilation is complete, the PVS-Studio analyzer launches quietly in background and checksthe modified files. It runs in background intentionally in order not to disturb the programmer. Staticanalysis takes more time to perform than compilation, so its no good making the programmer sighheavily watching the progress dialog. If everything is written correctly (both on your side and our side ;-)), the programmer will never notice that PVS-Studio is working.But we do have an error. Some time later the analyzer will signal a suspicious code fragment! It will getred and the programmer will but open the necessary tab to see the details:Indeed, you may read in the message that the condition is always false:
  3. 3. As a result, the error will get fixed almost right after being written.Please try the new mode of PVS-Studio. As usual, you may download the trial version here. If VS2010gets a bit slow after installation, reduce its appetite. The analyzer by default uses all the availableprocessor cores. So, you may specify in the settings how many cores can be used.Im anticipating some questions right now. Thats why Ive prepared a small FAQ at the end.1) Why does the new mode have support only in VS2010?Only Visual Studio 2010 has the API that allows you to determine which files have been modified andwhat files are dependent on them. In other words, a mechanism has appeared that allows you to choosethe files to be checked. You may read about it in detail here [1].If people like the new mode, we will think over as how to implement it for Visual Studio 2005/2008users too. However, I want to note that its much easier to switch to Visual Studio 2010 than it seems.You may select the old compiler but use capabilities of the new environment. This is achieved throughPlatform Toolset [2].2) Why not implement check on the fly straight away and underline errors immediately like it is done inIntelliSense?First, we do not have such a close integration with Visual Studio. To get it, we must be better friendswith Microsoft.Second, it wont do anyway. Static analysis is quite complicated and an analyzer must collect muchinformation on a rather large code fragment to detect some errors. Since the code is being edited, it willbe almost impossible to parse it. I think every programmer has seen how a C/C++ compiler goes mad
  4. 4. about one unnecessary parenthesis or incorrect template. C/C++ is not the right language to be analyzedabsolutely on the fly.3) What to do if I cannot tell green from red?A good remark. Well, in the next version there will be also a text written on the tab along with the colorchange.4) Why doesnt something work here or there?This is a new feature and some errors are highly probable. We will appreciate if you tell us aboutdrawbacks youve noticed and your wishes. The Feedback page.5) When Im performing Rebuild, will the analyzer check the whole project then?No. Its meaningless and too long. The analyzer ignores commands of solution and project rebuilds. Ifyou want to check a solution or project, you still may use the corresponding commands in the analyzer.References 1. Paul Eremeev. Using PVS-Studio analyzer together with Microsoft Visual Studio 2010 incremental assembly. http://www.viva64.com/en/b/0101/ 2. MSDN. How to: Modify the Target Framework and Platform Toolset. http://www.viva64.com/go.php?url=689

×