Signed word lengths and indexes

Steven Schveighoffer schveiguy at yahoo.com
Tue Jun 15 13:43:33 PDT 2010


On Tue, 15 Jun 2010 16:07:26 -0400, BCS <none at anon.com> wrote:

> Hello Steven,
>> Why?  If you can't understand/spot overflow/underflow problems, then
>> why  should I cater to you?  It's like lowering academic testing
>> standards for  school children so they can pass on to the next grade.
>
> The way peoples brains are wired, the first thought people will have  
> about that code is wrong. If that can be avoided, why not avoid it?

Because the alternatives are uglier, and it's not as easy to see subtle  
sign problems with them.  The code we are discussing has no such subtle  
problems since all arithmetic/comparison is done with unsigned values.

>
>> Why is it offensive if I expect a code reviewer to take overflow into
>> consideration when reviewing code
>
> That's /not/ offensive. For one thing, only very few people will ever  
> need to be involved in that. The reason I wouldn't let it pass code  
> review has zero to do with me not understanding it (I do understand for  
> one thing) but has 100% with anyone who ever needs to touch the code  
> needing to understand it. That is an open set (and that is why I find it  
> marginally offensive). The cost of putting something in your code that  
> is harder (note I'm not saying "hard") to understand goes up the more  
> successful the code is and is effectively unbounded.

So I have to worry about substandard coders trying to understand my code?   
If anything, they ask a question, and it is explained to them.  There is  
no trickery or deception or obfuscation.  I'd expect a coder who  
understands bitwise operations to understand this code no problem.

I would not, on the other hand, expect a reasonably knowledgeable coder to  
see subtle sign errors due to comparing/subtracting signed and unsigned  
integers.  Those are much trickier to see, even for experienced coders.

In other words, the code looks strange, but is not hiding anything.  Code  
that looks correct but contains a subtle sign bug is worse.

>> It's not some sort of snobbery, I
>> just  expect reviewers to be competent.
>
> I expect that to. I also expect people reading my code (for review or  
> what-not) to have better things to do with their time than figure out  
> clever code.

I guess I'd say that's a prejudice against learning new code tricks  
because not everybody knows them.  It sounds foolish to me.

-Steve


More information about the Digitalmars-d mailing list