Subtyping Primitives (or Abuse of the Integer)
A common source of bugs in the code bases I am working with lately (3d graphics in C# and C++) are related to the overloading of the notion of an integer.
In many 3d graphics libraries, like XNA, a common data representation of mesh data is an array of vertexes combined with an array of indexes into the original array.
In building an application in C# using the XNA game library requires that I keep straight whether I am dealing with indexes into the vertex array, or indexes into the index array. This gets confusing because in C# I had to represent everything as an integer.
I tried writing a struct to represent Vertex identifiers, instead of using raw integers, but the amount of extra code and complexity didn't really justify it. Anyone reading my code, would have just been wondering why the heck I wasn't using integers.
This isn't the first time that integers have given me a problem. In the C++ SDK for 3ds Max which I document, for example, there are lots of gotchas related to a distinction between identifier and index. For example parameter identifiers (ParamID which is typedef'd as a short int) are not the same as the parameter indexes. Because the parameter id's and indexes are often the same, this means that lots of code has latent bugs that only rarely occur.
A lot of bugs can be avoided if a programming language makes it easy and convenient to define new ordinal types. Effectively I want to write:
class VertexID : Int { }
And be done with it. I don't really see why this isn't yet possible in most languages.

