How to Learn Programming

Source: Internet
Author: User

This article will be a series that focuses on how to learn programming in the case of few external forces, as well as some areas that need attention.

In general, some so-called "Masters" or teachers will tell people that algorithms are so important that whether algorithms are the only criterion for programming. But not in fact. It is good to master algorithms, but most programs do not need advanced algorithms, and there are very few (and very difficult) companies that require algorithms ). I am not an academic student, so although I also advocate algorithm learning, I did not start learning algorithms.

People who are learning programming at the beginning always don't know where to start. In fact, this is a very important issue. In my opinion, learning well has several conditions:
· Interest
· Mathematics/English
· Financial Resources

First, let's talk about interest. Those who look for shortcuts to learn programming for their livelihood are not within the scope of this article. I usually don't care about these people. Interest is a very important condition, but interest can also be cultivated. A strong interest in programming allows you to find a variety of books, discover weaknesses in your knowledge structure, and communicate effectively with your peers. Those who are not interested only need code on the forum or QQ group when they encounter a problem (and most of them are grumpy ).

Math and English have no influence at the beginning, but when you learn something and get started with complex content, math begins to take effect. Many computer papers are written in mathematical languages. People who are not enthusiastic about mathematics or are not sensitive enough will have difficulty learning things they don't have in books. English is also important because not all articles or books are translated into Chinese, or translated into Chinese in time.

Financial resources are not the focus, but at least there must be idle funds to keep paying for network fees, books, computers, peripheral devices, and other essential items while at least feeding yourself.

As for the knowledge structure, my personal opinions may differ from popular opinions. At present, people always think of the knowledge structure as a pyramid. The bottom layer is the foundation. The above layer is more in-depth and professional knowledge, and the top layer is domain knowledge. The teachers will say they want to learn the basics, first learn the language and algorithms, and then slowly go up. I don't think so. I personally think that the "from left to right" learning method is more effective and will not miss anything, but it cannot be quickly achieved.

What does it mean from left to right? Imagine a pyramid, the leftmost is still the underlying [Foundation], and more [Foundation] and more upper-layer content will be involved to the left. In this way, there will be a continuous loop like [basic]-[upper layer]-[basic]-[upper layer. The advantage of doing so is that the results are fast and can cultivate a sense of interest and achievement, and the foundation gradually accumulates with the application needs. When the learning is successful, the Foundation will be covered, the things on the upper layer are similar, so you can go beyond the pyramid and soar.

Well, how can we cultivate interest?

People are always interested in interesting things. If it is not difficult to get started with such things, it is easier to accept them and cultivate a sense of accomplishment. According to the actual situation, I personally recommend that you learn C # when you first get started. The reasons are as follows:

· C # has many books, including easy-to-understand language kernels and rich class libraries.
· C # simple production Interface
· C # shields most tasks related to the operating system and the underlying layer, allowing the learner to focus on the content he or she is interested in.

If you don't have to worry about it, I thought it was unnecessary to look at the arrays and pointers of C/C ++ from the very beginning. In the future, I would naturally know about it. Another important reason why I recommend C # Here is Microsoft Visual Studio. net c # editor has an invincible list of beautiful prompts (according to a ". ), which is a good tool for beginners.

When learning C # At the beginning, you should first master a few basic syntaxes, that is to say, you should master the conditional statements, branch statements, function declarations, and arrays, plus the use of a small number of libraries and computing knowledge. Then begin to learn the production interface, and finally learn GDI +.

Learning GDI + has many advantages. However, you should read this book before learning. GDI + has some advanced functions, such as translucent effects and painting brushes. It is easy to combine some very beautiful images. After learning the basic operations of GDI +, You can gradually get in touch with some graphics filter, fragment, and 3D content. It is very interesting to use a flat tool to draw a simple 3D image. It is also amazing to exercise a lot of mathematical ability.

Then we should learn about string processing. Typical string processing involves analysis of INI files, operations on a four-digit formula, and so on. Although the C # processor string is a little worse than the C ++ string, it is quite useful to ignore this problem at this time, at least not to fall into the infinite pointer vortex.

When there are few graphics and strings involved, you can start to develop interesting programs. For example, you can use C # animations, develop function drawing tools, design a highly simplified HTML, render and create your own help programs, or develop simple image processing software. If you have the opportunity to write a lot of code every day, you will be able to come here for about half a year or a year.

Why do I choose between graphics and strings? To cultivate interest, you must first have a sense of accomplishment. Graphics and strings are nothing to do with the operating system itself, and there are no precautions for operations, so it is easy to get started. If it gets deeper, it will inspire enthusiasm for learning data structures, algorithms, and even math English. If you can use this main line throughout the preliminary stage of programming, it will be a solid foundation and flexible mind.

Well, let's talk about it today. Next time, write a new article. I would like to answer your questions here.

· Databases and networks are both popular. Do you want to learn more?
-- It is also a good thing to master these two technologies, and it is hard to get started. If you start from the very beginning, you may miss some opportunities to learn the underlying operating system and complex algorithms, because these two things won't give you the motivation to learn most of the deep knowledge.

· Why do algorithms not start learning?
-- What should I do if I have learned algorithms but no interesting questions to solve? In addition, the ultimate goal of learning algorithms is to give yourself the ability to design algorithms. Many people ignore this.

· Can I find a job after I have learned GDI + and strings?
-- No. Do not be impatient, do not learn programming in year 35 or do not take yourself too good.

· What should I learn next?
Continue with the previous article. If you follow the previous article, it is estimated that you have made some small software. Strings and graphics are easy to grow and attractive to the most promising programmers who subconsciously like mathematics. But these two things are not easy to do. When the program reaches a certain scale, the maintenance and efficiency issues will be highlighted. We are impatient to eat hot tofu. To solve the maintenance and efficiency problems that often occur, we need to learn algorithms and architectures. These two types of things can be learned at the same time, but there is not much to say in an article, so let's start with the algorithm.

Programmers need to broaden their horizons, and C # alone cannot. After all, the program runs on various platforms and has various languages. For example, native C/C ++ and Delphi on Win32 ,. net c # and VB. NET, as well as self-built Java, and then the COBOL running on mainframe, there are a variety of functional language, script language and so on. It is not difficult for people familiar with C # To start with Delphi. It is also possible to start with C/C ++. These two languages are originally in the local language. When programming, we need to pay attention to more things, typically memory management. This requires more exercises.

When it comes to algorithms, we will first recommend the second version of Introduction to algorithms. I found the Chinese version when I went to buy it a year ago, but at that time there were still some chapters without translation. I don't know what's going on now. If you are good at English, you can buy English versions.

Algorithms and data structures often appear together. Each algorithm is always implemented on different data structures to deal with different problems. In different languages, there are also some clever practices and general practices for various data structures that address actual problems. We can use STL, System. Collections. Generic, or ourselves. This depends on the actual situation. We cannot do better than STL, but STL is already quite good, satisfying the needs of most people. In specific situations, sometimes we have to implement the data structure on our own. If you use the method mentioned in the previous article to contact us, you have already written a lot of code and used a lot of less complex mathematical knowledge to train the foundation for linking theory with practice. With these foundations, we can easily learn algorithms and data structures.

Common data structures include linked list, list, stack, queue, binary tree, Balance Tree, heap, hash table, and graph. In addition, there are also various types of deformation, but the data structure remains unchanged. There are various algorithms around these data structures. Typical algorithms include sorting algorithms, search algorithms, pathfinding algorithms, and network streams. There are also some policy algorithms, such as greedy algorithms and dynamic planning. Policy-based algorithms are often used to create new algorithms. They must be understood and thought-provoking. I am not going to talk about the actual content of these data structures and algorithms in this article. The introduction to algorithms uses half a book to address these problems. It is good to read books and the articles are not detailed enough.

How do we choose algorithms? Just as I mentioned earlier, we need to relate our theoretical and practical experience. We need to look at the problems we need to solve from a mathematical perspective. If we find a concise representation to describe our problem, we also find the prototype of the data structure needed to solve the problem. Of course, this mathematics is not exponential analysis. I think it is closer to abstract algebra. Far away. Generally, we don't need to study these disciplines. We just need to feel it. A shortcut to cultivating feelings is learning mathematics. Of course, we can do things without learning. We can also learn how to do things through experience, but the path is longer. Readers don't want to learn mathematics, so they have no universal path. After finding the prototype of the data structure, the rest is the search algorithm. There are some algorithms that can be found in the book (for example, ACM is very fond of the questions ), some algorithms can be found in the paper (for example, non-universal algorithms created to deal with some complex problems), and the rest is derived by ourselves.

So, how do we learn algorithms? We learn algorithms only to solve practical problems, and to learn algorithms only when we encounter problems in the future. We do not learn algorithms for the purpose of learning algorithms. I have seen two different learning algorithms. The first is intuitive reading algorithms and learning, and looking for problems in the future. The other is to just take a look at the algorithm and then let it go. In the future, when there is a problem, we will open the corresponding algorithm for learning. The two methods are applicable to two different people, and there is no big difference between them. So we finally have to master an algorithm based on our own interests or needs. At this time, we can look for information, just as reading the article to digest the knowledge, and then write some small programs to test (or prototype, those who do software engineering like to say so ). This kind of small program is a discard prototype, which is discarded immediately after being written, in order to let yourself understand the content of the algorithm, check whether you have understood all the details required to execute this algorithm. When I feel that I can control this algorithm, I think it's almost the same.

Some people may think the algorithm is very complicated, because the algorithms in the book are very complicated. But the purpose of an algorithm is to speed up. Therefore, some good algorithms and data structures may become quite simple to combine, but it is not easy to think. Here are a few simple examples.

Friends who like to make graphics may like to play games. When we were a child in a simple 2D game, we always had to calculate whether there were a lot of people interacting with each other, or whether the magic that many people had given hit the enemy. If there are 100 people on our map, and each person has two moves, we need to check whether there is a collision (to determine whether an attack should be carried out) for 20000 times. This is obviously not acceptable. Then we can use the principle of divide and conquer. We can cut a map into multiple areas that contain humans and magic. Whenever people and magic move across the border of the area, people and magic will disconnect themselves from the previous area and link them to the new area. At this time, two linked lists are saved in the region. One is human, and the other is magic. Okay. How can I check if magic and humans collide with each other? You only need to check the data in the same region. If these 100 people are in 25 regions and each region has 4 people and 8 magic weapons, you only need to check 4x8x25 = 800 times, compared with the previous brute-force algorithm, this saves 96% of the time. Of course, this is just an ideal state.

Here is another example. We all think that C #, VB, and Java are amazing. They don't need to delete anything new, so it's quite comfortable. Suppose we want to implement this function now, we need to maintain all the new memory space, and execute a search algorithm to determine which memory space is no longer accessible and then marked, and finally delete all the marked space. Therefore, we need a memory manager for applying, marking, and releasing. How can we make it more appropriate?

Our memory manager needs to return a handle Based on the set length to represent the memory space. Then, we need to access the memory through the handle, Mark and delete these handles together. Why handle? If the pointer is directly returned, the execution of the language will produce a lot of memory fragments, and the new and delete operations are not fast enough. Now, we need the following data structures:

· A list of all newly deleted handles, which is used to quickly obtain unused handles.
· A list of all the handles in use, record pointers and lengths. This table is an array and the handle is an index.

When it is new, we query the first table to get an idle handle. If the list is empty, the second table will become larger (All handles will be used at this time) and the first table will be idle (that is, the first new space next to the original table) use the record tag corresponding to the handle. Then we always allocate the last point.
During the delete operation, we query all the marked handles to see if there are any marks. If yes, we mark them as not used and place the handles into the first table.
When we mark, we query the records corresponding to this handle, and then mark.
During collect, this is an operation to clear all memory fragments. We only need to traverse the table in the second chapter in sequence, move the useful content to the previous useless space, copy the data, and modify the starting pointer.

As shown in the figure below:
Idle handle: 1 2
Handle record: <0, 0 .. 9> <1, null> <2, null> <3, 40 .. 43>
Memory space: [0-9 bytes occupied] [10-39 not occupied] [40-43 occupied] [end here]

Well, we need to apply for a memory space. We get the handle 4 and need 10 bytes.
Idle handle: 1 2
Handle record: <0, 0 .. 9> <1, null> <2, null> <3, 40... 43> <4, 44... 53>
Memory space: [0-9 bytes occupied] [10-39 not occupied] [40-43 occupied] [44-53 occupied] [end here]

Now mark 3 and delete:
Idle handle: 1 2 3
Handle record: <0, 0 .. 9> <1, NULL> <2, NULL> <3, NULL> <4, 10... 19>
Memory space: [0-9 bytes occupied] [10-19, moved from handle 4] [end here]

Analyze the time complexity. In most cases, the actual implementation of the data structure occasionally has a slight deviation.
New is O (1), because the content obtained from the idle handle is O (1), the memory at the end of the allocation is O (1), find the record and mark it as O (1)
Mark is O (1), because the record is found and marked as O (1)
Delete is O (1), because you only need to mark
Collect is O (n), because the traversal handle records O (n), move the content, even if the maximum will move the entire segment of memory space, is also O (n)
Clause and obtain the memory address is also O (1)

We only need to use the win32 api to allocate a new large memory when the memory is insufficient. In this case, the memory manager shares the operating system quickly in most cases, this is also one reason why C # Does not obviously slow down as a hosting language. There are also some other reasons, such as. NET Virtual opportunity to temporarily compile some hosted code to cost code and so on.

For the third example, let's take a look at it. Dynamic Planning is a simple path-finding algorithm used to make a big job.

This article is about to end. We hold two examples to illustrate the following problems:
· Algorithms are often closely related to execution efficiency.
· A good data structure can exert the power of Algorithms
· Choose based on the actual situation, or even think about algorithms by yourself
· Algorithms are not all complex.

In fact, if you are not familiar with data structures and algorithms or have never heard of them, you cannot write some programs of a slightly larger size, but the programs written may be messy. It is better to learn algorithms on the development path of a programmer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.