Go to: A way to improve the developer's programming ability
The time was set back to May 2010 when I originally wrote this article at this time, which was posted on the fuel Your coding website. Unfortunately, this site is no longer present, so I re-publish this article here, considering the reasons why anyone would like to check it later. I have considered some changes to the content of the article, but it is good enough for me.
If you want to improve the ability to encode, one of the easiest ways to think about it is to write more code. Everyone knows this. However, another way that I think can definitely be improved is that it is entirely the opposite of this approach. I will explain this as clearly as I can:
Reading other people's code can make your coding ability significantly improved. |
Some people believe this sentence, and some people do not believe it. I think you should believe that. If you're willing to try it once, I think the rewards you get will be huge.
In this article I will tell you what kind of code you should read and make some practical suggestions to help you read it. If you are already good at reading other people's code, you may find new ways to read this article. What code should I read
This is a very important decision and a decision that is difficult to give. I can't simply tell you that you should read this code or that code, because it really boils down to what you're going to do. However, I will provide some guidelines to help you choose what you should read.
Read the code that you need
This step is best done by reading the plugins or library files that you are already using. You very much like the WordPress plugin you find useful in the Ruby Gem Toolkit You may also use to the jquery plugin
These are very good examples of what you can learn. You are familiar with their public APIs and understand that the barriers to how they work inside are low. In addition, as a user of code, you have the opportunity to add documents, implement new functionality, or generally contribute to a project in some way.
Read the code that impresses you
I remember the first time I saw the 280 slides slide site, I thought, "It's so impressive." "I quickly learned that the code for the site was based on the Cappuccino Open source project. I put this knowledge into the depths of my brain, and when I finally met another impressive but also cappuccino-based application, I knew I had a project that I could learn a lot from. What projects have you been impressed with recently? Is it open source? If so, this is a good reading choice, because the code will probably impress you.
Read the code written by the master that you respect.
If you have been coding for some time with open source software, you may already have other programmers who have earned your respect. In my mind I can think of some developers who write code that is simply admirable.
If you don't have a respectable developer in mind right now, it's not difficult to find one. He or she may have authorized some code in the first two sections (code you can use, or code that impresses you).
Read the code that will inspire you
If you are adventurous, consider engaging in large projects like Ruby on Rails, Drupal or jquery. But I suggest that you do not have access to such projects unless you are an experienced developer who is already very good at reading other people's code.
Large projects have more moving parts, and you may end up in trouble with these concepts, and you won't be able to learn anything of value. Confusion can lead to frustration, and larger projects are more likely to confuse and discourage you in reading. Choose a small project the benefit of reading is that you can put the entire program logic in your head at once. So you can focus on the details and learn a lot of knowledge. How to read
Now that you've chosen some code to read, what's the best way to read it? Here are some ways to maximize your ROI, that is, read less, but reap more.
First look at the big frame
Let's say you know at least at the macro level how the code you read is implemented. If not, I recommend reading the project's website, tutorials, documentation, and anything else that you can master in addition to the code.
Well, if the above steps are done, then I suggest that the first step is to take a rough look at the architecture of the project. The workload for this phase is different depending on the size of the codebase you choose, but it still takes a little time.
First, note the file structure. This step can help with some editors with a folder hierarchy view, such as TextMate. For example, here's a good overview of the Twitter Ruby gem.
The goal of this step is to familiarize yourself with the source code. Find out which files contain/request/load other files, where most of the code is, and if so, what namespaces are used, and what those properties are. Once you have mastered the big picture, you can dig deeper into the details.
Record reading experience
Reading the code should not be a passive behavior. When you start to understand the flow of the program, I encourage you to add comments at the beginning, documenting your assumptions and conclusions. When you start the first time, your record will probably be like this:
As your understanding progresses, you can delete some of the insignificant comments you left behind, and perhaps write meaningful, authoritative comments that might be submitted to your project.
Reading edge tests, such as Luke
I hope you have a test suite for the project you have selected. If not, you can skip this section completely (or find one).
When you read someone else's code, testing is a good starting point because they record the tasks that the code should complete. Some tests make more sense than other tests, but no matter how well written, you often find that the programmer's intentions in testing are much easier than they found in the implementation. While reading, try to make the test suite run successfully. This will ensure that your development environment is properly configured and that you are more confident when making changes.
Do it yourself.
Who says the hands are cannot when reading the code? You can really understand this process only when you're messing up everything and then trying to re-assemble yourself. Remember those tests that passed? Try to make them fail, add more, or try to change the logic of the implementation without destroying them. Try adding a small feature that you think is cool, or set the project-wide logging so that you can print the output at different stages of the code. Is this still reading? Of course, but at this point, it depends on your choice, see whether you take it as an adventure to see, or as a mysterious novel to see. This is a good thing.
Clear and repeat
Once you have finished reading a code base, choose one, and then start the process again. The more code you read, the more information you can get from reading, and the less time you spend. I think you'll find that the return on investment is growing fast, and it's a very interesting way to learn. where to start?
In the process of reading the code, the most influential factor for me is GitHub. This site makes it easy for you to find new projects and excellent programmers, and if you haven't used it yet, I think you are hurting yourself. I suggest starting with GitHub and then moving on to other websites to find a project that you think you can learn from. The next step is to start reading from Git clone.