On 11/19/14 4:24 PM, H. S. Teoh via Digitalmars-d wrote:
On Wed, Nov 19, 2014 at 04:08:11PM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 11/19/14 12:40 PM, bearophile wrote:
Andrei Alexandrescu:
There are related bugs in Java too, e.g. I remember one in binary
search where (i + j) / 2 was wrong because of an overflow.
This is possible in D too.
Also, Java does have a package for unsigned integers so apparently
it's necessary.
This is irrelevant. No one here is saying that a system language
should not have unsigned values. The discussion here is about the
type of array lengths.
I think we're in good shape with unsigned. -- Andrei
Implicit conversion between signed/unsigned is the fly that spoils the
soup, and the source of subtle bugs that persistently crop up when
dealing with size_t. The fact of the matter is that humans are
error-prone, even when they are aware of the pitfalls of mixing signed /
unsigned types, and currently the language is doing nothing to help
prevent these sorts of mistakes.
That I partially, fractionally even, agree with. We agonized for a long
time about what to do to improve on the state of the art back in 2007 -
literally months I recall. Part of the conclusion was that reverting to
int for object lengths would be a net negative.
Andrei