4 ms·
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 re
by clusmore 10y ago
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.
- nullc 10y agoCode is primarily for communicating between programmers, if it were mostly meant to be executed it would just be object files. Being a great coder means being adept at reading code however its structured. Reading unclear code is important because it helps you avoid making the same mistakes... it's also an important skill in practice: You will often encounter unclear code and have to understand it. The idea that there is one true good form is a misconception often held by novices. An expert should be able to read and write in a multitude of styles so that they can conform to whatever codebase they're working on and apply the best practices within that context.
- clusmore 10y agoThese are all great points, and I'm realising now I have missed the point a little. Reading arbitrary code is good, because you learn something regardless of whether the code is "good" or "bad" -- you learn how to understand more styles of code, and which patterns tend to be easy to understand and which tend to be hard. I guess the part that was tripping me up is that you shouldn't necessarily try to emulate all code you read.
- deleted 10y ago[deleted]