In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you an analysis of how to study the source code of nodejs. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Looking back on the source code research of nodejs, it has been more than a year. I like js this language very much, sometimes feel that it is the same as c language, in c language, a lot of things need to be realized by ourselves, so that we can exert unlimited creativity and imagination. Although js has provided a lot of things in V8, but with js, you can still create a lot of fun things, as well as fun ways to write. Js should be the only language I have ever seen that does not implement network and file functions. Or this function is not provided to the user. This is also my biggest prejudice against js. Because the network and files, is a very important ability. For programmers, it is also very core and basic knowledge. Because the usage scenario of js is running in the browser. If js provides file manipulation, it means that js can access the data on the user's computer, which is not displayed, so it is impossible for js to provide the ability to manipulate users' resources as we do in other languages.
Fortunately, nodejs was created. On the basis of js, nodejs uses the capabilities provided by V8 to greatly expand and enrich the capabilities of js. Especially networks and files. In this way, I can use not only js, but also network, files, and other functions. This is one of the reasons why I am gradually turning to nodejs. This is one of the reasons why I started to study the nodejs source code. Because nodejs meets my preferences and technical needs. At the beginning, however, I didn't devote myself to the code. I just occasionally looked at the implementation of some modules. The real beginning is to share. Since then, most of my spare time and energy have been devoted to source code research.
I started with libuv because libuv is one of the cores of nodejs. Because I have studied some of the source code of linux, and have been learning some principles and implementation of the operating system, I did not encounter much difficulty when reading libuv. The use and principle of C language functions can be understood basically. The focus is on the business logic, which needs to be sorted out. The methods I use are annotations and drawings. Personally, I prefer to write notes. Although the code is the best comment, I would like to take the time to use comments to explain the background and meaning of the code, because not every programmer can achieve the level of code that is comments. And comments will make it easier for most people to understand the meaning of the code. When reading libuv, I also interspersed some code of the js and C++ layers. The way to read the nodejs source code is to select a module and analyze it vertically from the js layer to the C++ layer and then to the libuv layer.
After reading libuv, the next thing I read is the code of the js layer. Although js is easy to understand, there is a lot of code in the js layer, and I feel that the logic is also very roundabout, so so far, I still have a lot of unread. This is a follow-up plan. In nodejs, C++ is a glue layer, very often, it will not censor, in fact, it does not affect the reading of the nodejs source code, because C++ is often just a transparent transmission function, he sends the js layer requests to libuv through V8. And then the other way around. So I didn't read the C++ layer until the end. C++ layer I think is the most difficult, the difficulty is not that I do not understand the logic of his code. But really understand how he works, at this time, I have to start reading the source code of V8, the source code of V8 can be said to be very difficult. I chose almost the earliest version, 0.1.5. Then combine the 8.x version. With early versions, you will first learn the general principles of v8 and some early implementation details. Because although the subsequent version has changed a lot, it is only functional enhancement and optimization, and there are many core concepts that have not changed. This is why I chose the earlier version to avoid falling into endless code at the beginning. I lost my way and lost my motivation. Even in the early versions, a lot of the content is still very complicated. The combination of the new version is because some functions are not implemented in the earlier version, so if you want to understand its principle, you can only look at the new version of the code. With the experience of the earlier version, reading the new version of the code also has certain benefits. I also know some reading skills more or less.
Most of nodejs's code is in C++ and js layers, so I'm still reading these two layers of code. Or vertical analysis according to the module. Read the nodejs code, let me know more about the principle of nodejs, but also better understand js. However, the amount of code is very large, which requires a steady stream of time and effort. So I have been looking for like-minded people to analyze and speed up the research on nodejs source code, but not many people can really eat the source code. Reading the source code may not necessarily help you improve your work, and most of the time you don't need to go that far. Unlike learning a framework or a language, we can see the results immediately, which greatly increases our motivation. Just as few people may learn c or C++ nowadays, it will not be easy to use the underlying language to achieve something that works. But with some scripting languages, we can quickly see what we want. The most important thing is that using more difficult languages will not increase our wages. Therefore, this is a matter of choice, not a question of right or wrong. It's a wonderful feeling to do technology and know why. It's not a good feeling that you make a living by a technology but know very little about it. Reading the source code will not bring you direct and immediate benefits, but there are several benefits that are inevitable. The first is that he will determine your height, and the second is that when you write code, you no longer see cold, inanimate characters. This may be a bit of an exaggeration, but when you understand how technology works, you do have different experiences when you use technology, and there will be more changes in your thinking. The third is to improve your learning ability, when you have more understanding and understanding of the underlying principles, when you are learning other technologies, you will learn more quickly, for example, if you understand the implementation of epoll, then when you look at nginx, redis, libuv and other source code, there is basically no too much pressure on event-driven logic.
The above is the analysis of how to carry out the nodejs source code research shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.