How do you read code?
Yeah. That's a question I was asking myself today. I am able to read code that I am looking at, but I have a lot of trouble kind of piecing all of it together. This happens a lot when I am reading scripts. I get the main idea, but there's so much going on and so much to get through that I feel kind of like I don't know where to start.
I'm thinking of this approach:
- Read the about to learn a bit about what it does.
- Read the help, to understand what kinds of options there are.
- Try using the script a bit and learn what it does.
- Now that I know what it does, I read the code itself and try to understand it as a whole.
- Now, I start looking at the pieces. What are the args? What are the imported modules? What are the functions? What do those individual components do? How do they fit together?
- Where is the user input? What does it do?
- Look at it again, and read it as a whole again.
It takes some time, but it helps me kind of structure and format everything. Doing this also helps me become a better coder. I get to learn how it's formatted. I don't know if there's a right way, but I figure it I see commonalities in code, it makes sense.