Don’t mix await and compound assignment

The 5.0 release of C# introduced the await keyword which makes it extremely easy to use Task<T> in a non-blocking fashion.  This allows developers to replace either blocking calls to Task.Wait() or complicated combinations of ContinueWith and callbacks with a nice simple, straight forward expression Task<int> task = …; int local = await task; Use(local);…

7

Not all “true” are created equal

  During a review of some low level bit manipulation logic a developer raised a question about the correctness of a piece of code which allowed any arbitrary byte to be seen as a bool.  No one could recall if true was defined as not 0 or simply 1.  If it was the latter then…

8

Yet another way to defeat C++ const

One of my favorite C++ features, and one I feel is terribly underutilized in many code bases, is the const mechanism.  It’s a great mechanism for defining dual roles for the same object type: a mutable and (ideally) non-mutable one.  But as useful as const is it’s also very easy to circumvent and I’m always…

2

Interesting Late Binding Scenario with ToString

Not to long ago I received an email from a customer who wanted to report a bug in the VB.Net debugger.  They believed that there was a bug invoking ToString on Integer types in the immediate window and provided the following sample as evidence i = 100 ? i 100 {Integer} Integer: 100 ? i.ToString("c02")…

4

Disable copy construction when the type is not copy safe

A couple of days ago I finished coding up a feature in our C++ code base, hit F5 and was met with a nasty memory corruption debugger dialog.  After about an hour of investigation it appeared one of my types was living past the lifetime of it’s owning heap. I decided the next step was…

5

Avoiding automation bugs when implementing IOleCommandTarget

Shortly after Visual Studio 2010 shipped I wanted to experiment with the new VSIX format for traditional Package extensions.  I fired up my copy of Visual Studio, ran through the new package project wizard.  But instead of a nice shiny new project I was greeted with a project load error dialog.  After a bit of…

0

Nothing is private in the debugger

The goal of the debugger is to provide rich inspection capabilities for a process.  The main method of inspection is through the evaluation of textual expressions which is handled by a language specific component known as the expression evaluator. This component is the data provider for a good portion of the debugger windows (watch, locals,…

0

Type safety issue when assigning CComPtr<T> instances

Recently while making a bug fix to our selection tracking code I discovered an unexpected behavior with CComPtr<T> instances.  The crux of the fix included creating a new tracking mechanism exposed via COM in the type ISelectionTracking.  The old interface, lets call it IOldTracking, was a completely unrelated interface in terms of inheritance hierarchies.  As…

1

Code Smell: Psychic classes

Psychic classes have the appearance of ignoring data provided to it in an attempt to provide you with an answer they predict is better for the situation.   It’s impossible to look at a the data provided to an instance of the class and understand what queries on the object will return because it may think…

0

Is it Serializable?

I’ve recently run across several APIs that have a dependency on only dealing with objects that are serializable (in the binary sense).  Unfortunately determining if an object is serializable is a non-trivial task and rife with problems.  These problems have a direct impact on the types of guarantees these APIs can make. For all objects…

3