How to Effectively Read and Understand Other People's Code
Asked by
SillySocks42
I'm looking for some tips on how to read and understand code written by others, especially when I'm trying to solve a problem. When I run into issues that I can't tackle on my own, I often turn to resources like GitHub or tutorials to see how others approached similar problems. However, I sometimes struggle to grasp which parts of their code I should apply to my own work. A lot of times, their solutions seem quite complex or unintuitive, and I'm left uncertain about whether I should create my own solution or incorporate their methods. Should I prioritize solving the problem independently before considering their approaches? Any advice would be much appreciated!
Answers
It really depends on the context. If you're working solo, using an established library is often the way to go. For example, if you need map projections or something like scheduling, there's usually a reliable library out there. Reading other people's code should mainly focus on understanding how it works and referring to the documentation, unless you run into bugs, which is common no matter the software.
If youโre joining a new team, itโs crucial to grasp the critical workflows and how different operations flow through the system. This can take time and may be challenging, and even experienced team members might miss details, so don't be too hard on yourself!
Reply to this answer
Youโre really tackling a vast amount of code here since thereโs so much variation out there. Some code is pretty straightforward, but then you have code thatโs complicated because of what itโs trying to achieve, or because the author didn't know what they were doing. It's definitely a case-by-case situation.
While you shouldnโt just copy someone else's code blindly, it helps to try to understand the reasoning behind how they've written it. Good code often comes with comments explaining why certain decisions were made.
Reply to this answer
Add your answer
Answers are reviewed before publication.
ThoughtfulTechie: Iโm not sure I agree that comments always help with understanding code. Good code can often explain itself well enough without needing too many comments. However, I do think bad code usually accompanies bad comments, so there's that!