Errata

The Art of Readable Code

Errata for The Art of Readable Code

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page 3
First two code fragments below "Is Smaller Always Better?"

The hard to read assert on the page is given as:
assert((!(bucket = FindBucket(key))) || !bucket->IsOccupied());

The easy to read version is given as:
bucket = FindBucket(key);
if (bucket != NULL) assert(!bucket->IsOccupied());

There two issues here which could lead to a serious program error.

1. In the hard to read assert, the first test has the side effect of assigning a value to bucket. If NDEBUG is set when the assert.h file is included, no code is generated for the assert which might leave bucket uninitialized.

2. The hard to read one line assert statement has two conditions, either of which can generate an assert. In the easier to read version only the second condition is checked. It misses the case where bucket is assigned the value NULL. There should be an extra assert line before the after the "bucket=" line and the "if" statement which would read:
assert(bucket != NULL);

As is, the code easy to read version could attempt to execute the remaining code with the bucket variable containing NULL.

Kevin Cozens  Apr 04, 2012 
PDF, Other Digital Version Page 27
2nd paragraph, example "SpaceLeft()"

"HasSpaceLeft" is still ambigous.
Does it mean there are spaces at the left side, or that there is space/room remaining?

"HasSpaceRemaining" might be better?

Christoph_P  Nov 30, 2011 
ePub Page 37
United States

Not so much a question as an observation: my motivation for using the ternary operator is to make it crystal clear that the purpose of these lines of code is to assign a value to a variable. This can be obscured by the clutter of an if-else block.

In other words, you use it to improve clarity and remove clutter, not to reduce lines of code.

I have Kindle ebook; which does not have page numbers. My Kindle tells me that this discusssion is at location 2007 of 5365, 37% of the way into the book.

Bob Stine  Sep 13, 2013 
PDF, Other Digital Version Page 137
Example under heading "The Infamous goto"

I understand this example exists to demonstrate an innocent use of goto, but couldn't/shouldn't that goto be elimininated altogether by switching the check on the IF from equal to not equal, and including the code block, rather than jumping around it?

At least, that's how I would do it. I assume there's a good reason not to do it this way?

Christoph_P  Dec 07, 2011 
Other Digital Version 140
First code example after heading "Removing Nesting Inside Loops"

There is a ">" in this line:

for (int i = 0; i < results.size(); i++) {>

apparently only in the ePub? The PDF doesn't have it.

Christoph_P  Dec 07, 2011 
177
TrailingBucketCounter class

It looks like the variable last_update_time is used uninitialized, i.e. the first time Update() is called it will do a shift with a calculation based on an uninitialized last_update_time.

Possibly misreading it but I don't see it being set anywhere except within Update()

time_t last_update_time; // the last time Update() was called
..
void Update(time_t now) {
int current_bucket = now / secs_per_bucket;

int last_update_bucket = last_update_time / secs_per_bucket;

buckets.Shift(current_bucket - last_update_bucket);
last_update_time = now;
}

Anonymous  Jan 17, 2012