How do you go about reading another person's code?

So learning how to code and reading my own code is one thing.
How do you guys go about reading another person’s code when other people uses completely different libraries, and techniques?

For me it’s the same as reading someone’s text in the same langauge.
Although I write diffrend when you write it’s still the same langauge so I would know how to read it. And figure out the meaning of it. Just like you are doing now :3

for different libraries, you need to consult the library documentation and be at least a littlefamiliar with it, or it would just be a nightmare
ideally the code should be well commented and variables named with good naming conventions…

in reality, practicing and hitting heads on walls

1 Like

I figured as much.
I find myself reading codes that is a collage of libraries overlapping each other that.
I’ll keep hitting my head against the wall. :dizzy_face: :dizzy_face:

So there are at least 3 levels of knowledge you usually need to know to read someone else’s code.

  1. Language Syntax knowledge. Knowing how the language syntax works will give you context as to the next 2 levels. Libraries aren’t magic, they follow the same rules as any language.
  2. The Domain knowledge. Knowing the code is fine, but do you understand the problem domain? Its one thing if the code is working with adding/removing todo’s from a todo list, but what if its calculating a Hohmann transfer burn? (yes I just gave an example from orbital mechanics :wink: ) You could understand the language syntax fully and still feel lost within the domain.
  3. The code’s structure/design/architecture. Knowing about the code AND the problem is fine, but you probably will need to understand some extra code beyond what your currently reading, as almost all code “builds upon” either libraries or other parts of the project. Take the nodejs express library, you will need to understand the api by reading the documentation to understand how its suppose to work. If your looking at code that uses express, then as long as you understand express your ok. But if your looking at code that does other stuff for other code, then you will need to potentially read more code to understand the more relevant code.

When starting out its easy to feel more “lost” as your lacking all three. The best way to get help is first understand which of the three you need help with, then looking into relevant resources. MDN is a great place for the 1st area (general JS syntax), the 2nd should be documented around the “idea” along with within the code base itself, the 3rd is probably the api documentation.

Good luck!

1 Like

if I have chances to talk about with the author, I try to figure out good questions (for that purpose, I make an effort to understand the code, even if it’s not my favorite one and being acquainted with the documentation info)
:slightly_smiling_face:

1 Like