Malcolm McLean said:
Kelsey Bjarnason said:
[snips]
The book doesn't contain the occasional error;
it contains consistent, repeated failures to grasp basic concepts,
then uses those failures to build code.
The most obvious examples are using int where size_t (or, at the
*very* least, unsigned) would be proper, and assuming ints have 32 or
more bits.
That was a writing decision.
Then it was a poor one.
unsigned integers have certain problems that can make algorithms with
them more difficult.
So do signed integers - for example, their behaviour on overflow. So if
you can't use signed and you can't use unsigned, what does that leave?
For that reason they were excluded from Java.
I have no comment on Java. They were not excluded from C.
There is of course some dispute about this, because ANSI mandates a
size_t to hold amounts of memory.
The only dispute is in your head. I've never heard anyone else, ever,
arguing that unsigned integer types are a bad thing.
The other problem is that once you admit one size_t it poisons
everything it touches.
No, the trick is to know when to use them and why to use them. Use the
right type for everything, and it all tends to come out in the wash.
For example, consider graphics. A frame buffer has a non-negative number
of rows (each representing a row of pixels) and a non-negative number
of columns (each representing a column of pixels). Since offsets into a
frame buffer represent row and column counts, it makes sense to use an
unsigned type.
On the other hand, sometimes you want to construct a world in which
negative co-ordinates make sense (e.g. a graph of tan theta). Since the
world needs negative co-ordinates, you need a signed type.
The frame buffer need *not* pollute the world, nor the world the frame
buffer. One simply determines that they represent different concepts,
and one then provides a mapping between them that doesn't violate the
integrity of either. Rendering a world view within the frame buffer
must involve mapping those negative values to non-negative values at
some point, so there is no real problem here at all. It's perfectly
okay to assign an int value to a size_t, you know.
So I decided not to use size_t at all, except once in the
introduction.
That decision was a mistake.