Stories
Slash Boxes
Comments

SoylentNews is people

SoylentNews is powered by your submissions, so send in your scoop. Only 14 submissions in the queue.
posted by martyb on Monday October 23 2017, @06:48AM   Printer-friendly
from the MY-code-is-perfect! dept.

I am really astonished by the capabilities of static code analysis. The tool surprised me the other day as it turned out to be smarter and more attentive than I am. I found I must be careful when working with static analysis tools. Code reported by the analyzer often looks fine and I'm tempted to discard the warning as a false positive and move on. I fell into this trap and failed to spot bugs...Even I, one of the PVS-Studio developers.

So, appreciate and use static code analyzers! They will help save your time and nerve cells.

[Ed note: I debated running this story as there was an element of self-promotion (aka Bin Spam), but the submitter has been with the site for a while and has posted informative comments. Besides, I know there have been far too many times when I've seen a compiler complain about some section of my code and I'm thinking there is nothing wrong with it — and then I, finally, see my mistake. Anyone have samples of code where you just knew the compiler or static analyzer was wrong, only to find out otherwise? --martyb]


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 5, Interesting) by fyngyrz on Monday October 23 2017, @04:27PM (1 child)

    by fyngyrz (6567) on Monday October 23 2017, @04:27PM (#586395) Journal

    Mistakes don't just come about due to inexperience. There are whole rafts of typos that are valid code, but will break stuff. There are mistakes in recall about side effects. There are misunderstandings of documentation.

    I pulled a whammy the other day, after not looking at objective c for some time, I went in to do something that should have been fairly easy, got a message from the compiler, completely misunderstood what it meant, and got myself into a hole it took two hours to dig out of plus posted a sadly clueless question on stack overflow for which I got snarked fairly hard, predictably. And I probably have more programming (and hardware) experience than most - about 45 years worth. Once I wrapped my head around what had happened, of course, no problem. But I did make the error.

    As the GP stated, we all screw up now and then. Best not to dive into a well of hubris, lest one drown in it some fine day.

    Starting Score:    1  point
    Moderation   +3  
       Insightful=1, Interesting=2, Total=3
    Extra 'Interesting' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   5  
  • (Score: 2) by maxwell demon on Monday October 23 2017, @11:12PM

    by maxwell demon (1608) on Monday October 23 2017, @11:12PM (#586639) Journal

    Mistakes don't just come about due to inexperience. There are whole rafts of typos that are valid code, but will break stuff. There are mistakes in recall about side effects. There are misunderstandings of documentation.

    That line is not just a typo; the typo in it is the only thing in it that is excusable. It definitely is neither a mistake in side effects, nor a misunderstanding of documentation. It violate a whole range of rules which every C++ programmer should know by heart. And those are not violated by accident.

    --
    The Tao of math: The numbers you can count are not the real numbers.