I'm not sure this is a fair comparison, because books are written to be
read, but code is (usually) written to be
executed. As much as we all agree that code readability is important, the simple fact of the matter is that executability matters a helluva lot more. We're paid to write code that executes, and many people stop there.
The result is that there is a lot of code out there that executes just fine but is completely terrible to read, and I wouldn't advise learning from. And the problem is, especially for beginners, it's difficult to determine which is which.
Add to this the fact that code changes over time, in more ways than one.
1. It physically changes, i.e. we commit changes to it, so a codebase that is well written today may be dramatically changed tomorrow.
2. The context changes, i.e. the circumstances that make one tradeoff better than another change all the time, and if the context isn't captured effectively, it's difficult to understand when good decisions change to bad ones.
3. The language changes, i.e. new versions or even entirely new languages come out which fix mistakes in old versions or languages, so good code today may be difficult to learn from in the future if the language is no longer well understood.
We need more collections of repositories that are agreed upon as "good quality" that everybody agrees are worth reading and learning from.