Read More Code

15 May, 2019

When you were young and learning how to write, the teacher didn't just teach you the alphabet and then told you to go write something. The first thing you do after you learn your letters is to read. You were told to read lots of books and to continue reading. Then when you do start writing you continue to read.

This is similar to learning to code. Once you learn some syntax and understand something you can go off and start writing code. I am not suggesting that you have to read a certain number of repositories before you can start writing. What I am suggesting is that you can learn a lot from reading other peoples code.

Read Others Code

Find code that is considered good. There is a lot of code out there and if you are reading bad code you will probably write bad code as well. On the other side there is a lot of code that you can learn from out there. Github and other git repositories have a unlimited supply of code projects to learn from. I would suggest that you start on smaller projects and work your way up. Maybe there is a library that you use in your code and don't even think to how it works. Don't be afraid and get into the code and read how it works. You might not understand it all but you also might be surprised how much you can learn from it.

You can learn so much from reading others actual code. When you are learning a new language or framework it is great to read the documentation and other resources, but it doesn't quite give you the context of a real project. Reading code in an actual project can give you an idea of how code should be used.

Look at the how the code is structured in folders and how the code is organized in the files. One thing I learned from doing this is that real code isn't perfect. Not that we shouldn't be striving for great code, but you will find that sometimes you just need to get it to work.

Run the Code

One of best ways to read code is to get it running locally and then to step through the code. I like to setup a debugger and step through the code line by line and as I read each line try and guess what is going to happen next. I try and think about how the conditional statements will resolve and what variables will be after executing the code.

Then you can go ahead and change things about to see how they react if it doesn't turn out the way that you thought.

Reading Code Can Deepen Your Understanding

There is a large variation in the quality of documentation that accompanies code. Sometimes you will have top notch documentation like from the vue team and then you will have documentation that just doesn't make sense. If you have access to the source good, being able to read it can be a great skill to have. When the docs are not making sense I simply go to the code and read what is going on and it can clarify things that don't make sense.

So don't be afraid of source code like I was when I started out. Jump in it won't hurt and it will only be a benefit to you.