DEV Community

Discussion on: Is it worth reading source code?

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

I do believe in reading source code for two reasons:

(1) You should understand any abstraction you lean on. (However, decent documentation usually removes the need to read the source, as iedaddy said).

(2) You learn a lot from reading code.

However, I don't have time to read it all. So, in the end, there are three situations that will lead me to read source:

SCENARIO 1: Epic code! I love reading code bases that I can learn a lot from. I especially enjoy combing through standard library implementations. Honestly, I want to start doing this more.

SCENARIO 2: Terrible code! If I want to learn why something is so unstable, inefficient, or otherwise terrible, I'll dive in and see what I can learn not to do.

Some people ask me why I prefer Clang over GCC. Reason #1, the source for GCC is some of the scariest cruft-ridden spaghetti I've ever read, while Clang is clean and modern. Which foundation would you rather build your house on?

SCENARIO 3: Important code! Whenever I'm working on a fresh implementation that is functionally similar to existing open source code, I'll often look at the original implementation to learn how it works. I'll also read the code if I rely so heavily on it, I need to understand how it works. (You should seriously consider this if your entire project's functionality hinges on one implementation of a library or algorithm.)

As a side note, there is no faster way on this planet to learn a programming language than to jump into mature source with nothing more than the project documentation and the official language docs.