Efficiency of examples
Chapter 10: Extension methods: 10.3.2
Last updated: 3/4/2008
Before technical review, the query in listing 10.8 called
Reverse - in other words, it was inefficient. I knew about this, and already had the callout to explain how the efficiency could be improved, but Eric suggested that the code in the listing should be the more efficient code to start with.
His reasoning (which I totally agree with) is that sometimes developers take code directly from books, and then fiddle with it until it works for their particular situation - sometimes without reading the surrounding text. Therefore the examples should avoid errors which are then pointed out in the text.
The moral of the story is two-fold:
- If you're a writer, follow Eric's advice - bear in mind that people may well blindly copy and paste code.
- If you're a reader, assume that the author doesn't follow this advice. Always make sure you understand any code that you lift, and read the explanation in the book (or article, or tutorial etc).