Happy blogoversary

Good heavens, I blew past my tenth blogoversary without even noticing it. My first blog post was on the 12th of September, 2003 and looking back I see that I made a whopping 36 posts in the two weeks that followed. That’s craziness; my publishing rate is now about a tenth of that. But of course then I had a huge backlog of material to publish that I had been collecting for years, so there you go.

Thanks all for helping me during my fabulous adventures; I appreciate it very much. Here’s to another ten years!

ATBG: interfaces and increments

On today’s episode of the Coverity Development Testing Blog series Ask The Bug Guys we have two posts. I take on the question does explicit interface implementation violate encapsulation? and my colleague Jon follows up on my previous posting about increment operators to discuss the precedence of the increment operator and bonus, the meaning of local static in C/C++.

As always: if you have a question about some aspect of C, C++, C# or Java programming language design, or want to share an interesting bug that bit you in one of those languages, please send it (along with a concise reproducer of the problem) to TheBugGuys@Coverity.com. We cannot promise to answer every question or solve every problem, but we’ll take a selection of the best questions that we can answer and address them here every couple of weeks.

Math from scratch, part six: comparisons

Getting equality correct is surprisingly tricky in C#. The landscape is a bit of a confusing jumble:

  • The == and != operators are a syntactic sugar for static method calls, so it is dispatched based on the static (compile-time) type of both operands.
  • object.Equals(object) is a virtual method, so of course it dispatches on the runtime type of its receiver but not its argument. An override on a type T is required to handle any object as an argument, not just instances of T.
  • IEquatable<T>.Equals(T) by contrast takes a T.
  • For reference types, you’ve got to consider comparisons to null even if it is an invalid value.

That’s four ways to implement equality already and we haven’t even gotten into IComparable<T>.CompareTo(T), which also needs to be able to compute equality. Continue reading

Testers wanted

I’ve been at Coverity for nine months now and the Seattle office has expanded from me and Bob to nine developers and testers; it’s been very exciting to help grow this office from a couple of guys with laptops to what will soon be a fully-fledged branch office. We’re shortly to move out of our temporary space on the 42nd floor of the Columbia Center to a larger space on the 12th floor.[1. Unfortunately downgrading my view from absurdly spectacular to merely totally awesome. I’ll post pictures when we move in next month.]

We are looking to fill a few more positions in the Seattle office, and particularly looking for a tester to work on automating testing for our Visual Studio plug-in and other GUI front ends. If you fit the bill and would like to work with me and the rest of the awesome team we’re assembling, please check out the listing here. A complete listing of all open positions at Coverity can be found here.

Do feel free to drop me a line, or leave a comment below, or note in your application that you heard about this on my blog. Please do not just send me a resume; use the link in the job posting so that our recruiting team gets the information as soon as possible.

How to learn a new programming language

The nice people over at InformIT recently asked a bunch of authors of programming language books for advice on how to learn a new (to you) programming language; they were kind enough to ask me my opinion which I happily gave. Check it out here.

My candidate for best quote is from Bjarne Stroustrup: It is not easy to tell good advice from the far more plentiful harmful nonsense. It’s true! And that is good advice.

ATBG meets math from scratch

In a nice bit of synchronicity my article this week on Ask The Bug Guys, our continuing series on the Coverity Development Testing Blog, is about the differences between the C, C++ and C# interpretation of the ++ operator[1. And of course everything in there applies equally well to the -- operator.] So read that first, and then it will make perfect sense why the increment operator on my Natural class from last time is simply:

public static Natural operator ++(Natural x)
{
  if (ReferenceEquals(x, null))
    throw new ArgumentNullException("x");
  return Add(x, One);
}

As always, if you have a question about a bug in a C, C++, C# or Java program please email it to TheBugGuys@coverity.com along with a concise reproducer of the problem if possible. We can’t answer every question but we’ll pick a sample of the most interesting ones a post an analysis on the dev testing blog.

Next time on FAIC: multiplication.

Math from scratch, part three: natural addition

Last time in this series we built a Natural object that represented a number as a linked list of bits, with the least significant bit in the head and the most significant bits in the tail. We use the “null object pattern” where a Zero tail represents that the remaining bits in the sequence are all zero, and the sequence of bits never ends in a zero bit followed by Zero.[1. If that sounds different than what I wrote the last time, reread last week’s post. I slightly changed the organization of the structure based on a reader suggestion.]

So let’s then divide our implementation into two parts, one which enforces the public part of the contract that null is meaningless:

Continue reading

Math from scratch, part two: zero and one

Last time I said that I was going to choose the “sequence of bits” technique for representing a natural number. At this point I don’t think I need to go into detail about how bits work; you all know that each position represents the addition of a power of two multiplied by the value of the bit at that position, blah blah blah. Let’s instead concentrate on the technical details. Continue reading