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.
Getting equality correct is surprisingly tricky in C#. The landscape is a bit of a confusing jumble:
!= 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
Ok, addition and multiplication are in the can. Those are the easy ones because the set of natural numbers is “closed” over those operations. That is, if you have any two naturals then both their sum and their product is also a natural. Not so subtraction! To see why, first we have to state what subtraction really is. Continue reading
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.
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.