If you want to become a writer, it’s not enough to simply know grammar. You also have to read a lot of quality books that will show you how this grammar is used in practice to create brilliant eloquent texts.
Similarly, if you want to be a good programmer, it’s not enough to simply learn some programming language and tools. You should also read quality code of programs written by other programmers.
When it is about becoming a writer, reading books is rather the first step of your education. You can read even if you don’t know grammar, and naturally “absorb” it without knowing the rules.
In programming you’ll be able to learn from other people’s code only when you already have a solid prior knowledge in this domain. Otherwise it’d be just too hard to understand properly what you read.
This is definitely the most difficult way of learning programming. So this is not something you should begin with.
But it’s invaluable when you’re ready for it. This time usually comes when you’re already working on some real project and have at least about a year of experience as a programmer.
Explore code of popular modules you’re going to use in your project
If you’re using in your project some popular free open-source module that does some particular job (shows the images in the convenient gallery interface, uploads files to the server, etc.), explore its code before including it in your project.
It will not only give you the understanding of how this part of your project will actually work, so that you won’t be using some enigmatic “black box” that just somehow does what it does. It will also provide you with useful insights about how it’s done. This will significantly improve your knowledge and skills as a programmer.
Reading such code at first might be pretty difficult, since it is usually not written in a way that any beginner programmer could easily understand it. It’s not a learning material per se, it’s just meant to do its job.
So it’s normal if you, as a beginner programmer, cannot understand what exactly some particular part of the code does. Just try to grasp the main logic and meticulously study those parts of the program that seem quite clear to you.
Leverage your current high motivation
You’ll never be more motivated to understand how this ready-made module works “under the hood” than now, when you need this solution and when you’re immersed in the task.
So this is a perfect chance to learn something new. And it’s not some random programming fact or technique that might be learned just in case, but the one that you need right now.
Thus your brain is ready to process the information without much additional efforts. Maybe, it even has already done a great deal of preliminary work of thinking over possible ways to do this particular job.
Reading other people’s code will boost your confidence
If you read the source code but understood nothing — that’s fine. It simply means that you’re not ready yet, but at least you tried.
But if you did understand the code, then as a bonus you get a great boost in your confidence as a programmer. If you can figure out exactly how some popular program “from the real world” works “under the hood”, then you definitely already know a thing or two about programming.
But don’t try to lift weights that are too heavy for you at the moment, like the code of really big applications or, say, operating systems. Such an experience would be rather frustrating than useful and inspiring, because the code will be very long and complicated, with complex structure.
Also pay attention to the way the code is structured, formatted, and commented. It may give you additional ideas about how you could improve your own way of writing code.
How the habit of reading other people’s code will bring you to the whole new level of programming
Reading the code of modules you use in your projects will also help you gradually gain courage to modify other people’s code so that it fits your needs perfectly (of course, if the license under which you use the code allows you to modify it; the type of the license usually is clearly stated in the beginning of the source code file or in a separate file the source code is bundled with).
It will not only save you a lot of time that otherwise would be spent on creation of custom solutions from scratch, but will also open for you the door to the whole new level of programming, where you’re no longer limited by decisions made by authors of many popular free open-source modules.
Important skill for professional programmers
If you’re going to pursue a career as a programmer, the skill of reading and modifying code written by other developers will be very important — one of the most crucial ones, actually.
Big projects you’ll likely be working on are rarely created by a single developer, so you’ll inevitably be working in a team. In order to write code for your part of the application, at times you’ll have to carefully read source files created by other members of your team.
If you want to work on big enterprise level software (banking software, ERP software, CRM software, etc.), then chances are that reading and modifying other people’s code will take a significant amount of your working time. Such software is usually quite old and requires constant support: to fix bugs, to add new functions to thousands of already existing ones, etc. Any of such tasks require deep examination of the existing code base.