Some advice that hasn't been mentioned yet: make sure your publisher supports you. Writing a book is difficult and you want to spend your time on the content -- not making sure that there are no typos, teaching the publishers how to run the code, doing the layout, maintaining different versions of the book, etc. I recently wrote a book, and I got very little support from the publisher. It was a disaster, although I d…
Not only did they successfully kill jrock's book but based on his contributions to the project and associated work they also killed his motivation.
So: good publisher, thick skin, pick two or don't start.