Jeff Atwood over at Coding Horror is always going on about how programmers don't read programming books because most of them suck, and I agree with that. I personally have only read about three really good ones.
In Jeff's post, he mentioned (as an example of poor writing) a book called Perl for Dummies. I followed through to the linked review, and it was great. So I wanted to point out a few of the best (of the worst) examples, as I think programmers who are writing should take notice of these kinds of things.
When there are simple and difficult explanations, you can usually count on Hoffman to find the difficult explanation, and then to tell you how difficult is. For example: (page 93)
intcan be a bit tricky because it rounds down for positive numbers and rounds up for negative numbers.
He's right; that is tricky. Wait, which was does it round again? Up, down, positive, negative, I can't remember. But if he had said
intis very simple: It throws away the fractional part of a number, leaving the integer part.
then it is a lot easier and you understand the name so that next week you might remember what it does. Another example of this: In the ill-advised explanation of
xor, he saysThe operator returns true if the two things have different truth values but returns false if they have the same truth value. (See table 8-2.)
Here's the simple version:
$soup xor $saladis true if either
$saladis true, but not both.
Then you dispense with the table.
Part of the reason Robert and I do Develocity is because we are always finding terrible sample code out in the wilds of the Internet, and it's teaching programmers the wrong ways to do things. It's scary to think people are filling books with the same sort of nonsense.
I'm not a programming expert, and I make my share of mistakes too, but before I post sample code that other people are going to look at and possibly use, I will go through it a few times, seeing if it can be made simpler and easier to understand.
Most examples have too much noise. A "Hello, World" example should do nothing but print "Hello, World" to the screen. Don't add any for loops or random number generators to it.