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!
2 Answers
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.
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!

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!