If you'd like to become a good writer, it's not enough to know grammar. You also need to read lots of books that will show off how this grammar is used to create prominent texts. Similarly, if you'd like to become a good programmer, it's not enough to simply learn Java. You also ought to read lots of quality code samples written by other programmers, and most importantly, understand and learn from them. Actually, exposure to high-quality examples of codes is one of the key factors that influence how quickly and effectively you'll learn new skills.
Importance of Reading Others' Codes
"I hate reading other people's code" is a common mistake that Java developers of all experience levels make. However, it's a very welcome skill, especially for those who'll be rolling onto existing codebases or are planning to work on big enterprise-level software. The thing is, most likely, you'll need to constantly modify other people's code to fix bugs or add new features to a myriad of already-existing ones. And all these tasks call for deep examination of the already-existing code base. But if you have the right strategy and the right tools to work with it, copying or modifying others' codes can be an enjoyable and advantageous experience. As a learner, you can get a fantastic experience by simply reading codes written by Java specialists. They will give you an understanding of how any part of the project works and provide you with useful insights about how it's done. This, in its turn, will help you significantly improve your knowledge and eventually develop your own style.How to Dig into Code
When you're diving into others' code, you may feel more like an archeologist-investigator rather than a developer. There is nothing wrong with that as you've got lots of "shovels" at your disposal. Nowadays, you have access to a lot of metadata that will help you understand the code much easier. For example, you may use Git to help yourself when reading, copying, and pasting the code. Yet, some key points can help you understand the code better initially. First of all, you should ask the following questions:- Is there anything in the code that looks unfamiliar to you? If so, review those "blank spaces" and make sure you understand what they are used for.
- Is there anything unnecessary in the code? Dead codes also exist, especially if we're speaking about large codebases.
- Does the code have any dependencies? Sometimes it's better to remove that dependency by copying/pasting even more code.
- Are there any errors that occurred after pasting?
- how the body of code is actually built;
- the style of coding;
- how the programmer who wrote the code solves the problems.
Run the code and explore the results. Running the code will give you the essential information you'll need to understand it better.
Find its main function and the start point.
Run the code with the debugger (you may find the most efficient Java debugging tools here) to fully understand the code's mechanics. By doing so, you'll get an in-depth analysis of the inner functionality of the code you're reading.
Build a mindmap of the connections between different elements in the code. As any debugger will show you a connection between the elements, you'll be able to correlate different functions and understand how they interact with each other.
GO TO FULL VERSION