Fix compare methods and use type_code in __cmp__

Perhaps we can change the comment to something like:
```c++
// We return the order given by the (arbitrary) numerical value of the TypeID enum type.
// The types don't need to be ordered in any given way, they just need to be ordered.
```