The Uncommon Case

An Interview with Ben Chelf from JavaOne 2007

by Frank Sommers and Bill Venners
June 7, 2007

Summary
Developers think a great deal about the expected behavior of code, but expand much less effort on pondering the unusual conditions that could lead to bugs and software defects. According to Ben Chelf, CTO of Coverity, spending more time on thinking about the uncommon cases would result in higher-quality code.

While bugs creep into code for a variety of reasons, a lot of those causes are a result developers not fully understanding the code base they're working on, leading them to wrong assumptions, according to Ben Chelf, co-founder and CTO of Coverity. Chelf's company makes a static code analyzer, giving Chelf a good vantage point from which to observe common causes of programming errors.

In an interview with Artima, Chelf said that misunderstanding occurs when developers expect code they're calling into to behave a certain way, only for that code to act in a somewhat unexpected manner:

A lot of the problems we find [occur] when there are discrepancies between what a user of an interface and the implementor of an interface agree on. If there is inconsistency there, that will lead to problems. Maybe I didn't think I had to do certain checking of parameters that I pass into another function. The person who implemented that method might have thought that those parameters would always be checked before they were passed in...

Many of the problems we identify... are because of the developer not thinking about all the different possibilities that could be true or not true when calling into a different interface or when a certain path happens...

I think developers, for the most part, don't think enough about what is going to happen in the bad case. We all have the tendency to think about the common case, the average case. Those are the ones that are going to run in your test suites. Those are the ones that are the likely behavior. But you have to spend probably a lot more time coding and thinking about the uncommon case, and what can go wrong in your system, and how things could possibly be used in a way that you didn't anticipate.

Click to download audio Ben Chelf, CTO of Coverity, talks about the importance of thinking of the uncommon cases.

How much effort do you typically spend on thinking through the unexpected and uncommon cases your code may encounter?

Post your opinion in the discussion forum.

Talk back!

Have an opinion? Readers have already posted 20 comments about this article. Why not add yours?

About the authors

Frank Sommers is Editor-in-Chief of Artima Developer. He also serves as chief editor of the IEEE Technical Committee on Scalable Computing's newsletter, and is an elected member of the Jini Community's Technical Advisory Committee. Prior to joining Artima, Frank wrote the Jiniology and Web services columns for JavaWorld.

Bill Venners is president of Artima, Inc. He is author of the book, Inside the Java Virtual Machine, a programmer-oriented survey of the Java platform's architecture and internals. His popular columns in JavaWorld magazine covered Java internals, object-oriented design, and Jini. Bill has been active in the Jini Community since its inception. He led the Jini Community's ServiceUI project, whose ServiceUI API became the de facto standard way to associate user interfaces to Jini services. Bill also serves as an elected member of the Jini Community's initial Technical Oversight Committee (TOC), and in this role helped to define the governance process for the community.