A large portion of programming books are still under neither a FOSS nor a CC license, and hence fully protected by copyright. (I've encountered some where the main text of the book is not under a FOSS license, while the code is, but that's also not universal.) In such cases, you're not allowed to just re-use large code segments from the book (commercially or in an open source piece of code). Hence the case of a book under GPL isn't any "worse" than that, except that you do have the option of using the code in a GPL-licensed codebase.
(Small snippets are obviously not covered by copyright.)