Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Why do I suck at reading code and how can I get better at it?

I am fairly good at writing code that works without much trouble. But when it comes to reading and understanding code written by others (or my own code that I didn't properly comment), I struggle a lot. Even for just a few lines of code, I have to read it over and over again several times until I have that "Aha! I get how that works" moment. Of course this isn't so much for really simple lines of code, but functions that run more than a couple lines, etc. I think my working memory is average at the very least, so why do I struggle with this so much?

I have been writing (and reading) code for a little over a year now and I haven't gotten much better at it. Is there any strategy I can use to understand code faster when I read it? Does anyone have any tips? Much appreciated!

Honestly bro....to keep it 1000%. You probably will always read something over and over and over until you get that light bulb. ESPECIALLY if the author writes complex spaghetti code without comments. Do not feel bad about this. I build features and clean up complex code every day at work...guess what? I read code more than once sometimes. Scratch that my manager gets stuck and pulls me into a meeting to help her figure out what the heck she is staring at. Oh, to calm your nerves some more I work with a director on my team (15+ years exp) who read code more than twice.

I have been working as an engineer professionally for 3 years and I will say going into my 2nd year I was able to look at something and know exactly what it is going on. But look at what it took to get there; I worked over 8 hours a day, the first few months I work 6 or 7 days (big release happened when I started) and I am now familiar with the code bases for each project and I know the flow of things.

To sum things up just keep practicing do not worry about the negative. You are awesome and you will do great!

Cheo R
Cheo R
37,150 Points

When I first started, (for small projects), I used to print out the code, trace its execution, and write comments in the margin of what I think it's supposed to do. Then run the code and compare it to what it actually executes.

Then I started adding print statements. Print statements everywhere.

I don't do either as much now, but still do so with code that stumps me.

I suggest also going on github and looking at other peoples' code to see how much of it you understand.

Steven Parker
Steven Parker
231,007 Points

Kristina McElveen and Cheo R — you've both left good advice but why not post it as an "answer" instead of a comment? That will allow voting plus Michael can choose one as a "best answer" if he wishes.