Do courses like Data Structures and Algorithms, Operating Systems, Principles of Compilation, and Principles of Computer Composition need to be taken for the average programmer? What will they help?
Let’s take these courses in turn to understand what is useful in the work, the answer is a little long, please remain patient:)
I. Data structures and algorithms
As Professor N. Wirth said: Data Structures + Algorithms = Programs.
When you encounter a practical problem, make full use of the data structures you have learned, store the data and the relationships between them in the computer effectively, then choose the right algorithmic strategy and use the program to implement it efficiently.
This statement may be a bit abstract, so let me explain it to you with an example.
In the course of our work, we have more or less come across OAuth2, and when using OAuth2 authorization, usually the application will pop up a message like this
1) Get basic user information interface
2) Get user list interface
3) User group management interface
WeChat Get Authorization
Think about it, if you are asked to design a database, how should you design the information storage permissions?
If you have mastered the characteristics of various data structures, it is natural to think of using bitmap to store permissions.
After we divide the permissions into the smallest granularity, each bit has its own meaning, for example, we divide the permissions into the following.
To ensure scalability, we use a uint64 to store these bits, which means we can divide them into a total of 64 subdivision permissions, and then combine them.
For example, if the first bit is set, it means you can get your nickname, avatar, region, gender and other basic user information, and if the second bit is set, you can send status with your identity.
There are many more practical uses of data structures, so if you are interested, you can search for the following knowledge points.
Binary tree search for interrupt processing, registration cache lookup, etc.
Hash tables for implementing index nodes, file system integrity checks, etc.
Red-black trees for scheduling, virtual memory management, tracking file descriptors and directory entries, etc.
Radix trees for memory management, NFS-related lookups, and network-related functions
These examples above are about data structures, I’ll give another example of an algorithm, if it helps, you may want to click a favorite, good content deserves recognition.
The same to think about a problem: no matter how large the computer’s cache capacity, the cache is full or to delete some content to make room for new content.
So what content to delete? We definitely want to delete the cache that is not useful, and keep the useful data in the cache for further use. So, what kind of data do we consider “useful”?
The strategy we adopt at this point is the LRU cache elimination algorithm.
The full name of LRU is Least Recently Used, which means that we believe that recently used data should be “useful” and data that has not been used for a long time should be useless, and when the memory is full, the priority is to delete data that has not been used for a long time.
II. Operating System
Let’s first look at what an operating system has to offer.
A modern computer system consists of one or more processors, main memory, printers, keyboards, mice, monitors, network interfaces, and various input/output devices.
To be honest, it is impossible for a programmer to master all the details of a computer system, so on top of the hardware, the computer is installed with a layer of software, which is capable of controlling the hardware by responding to user-input instructions to meet the user’s needs, and this software is called an operating system, and its task is to provide a better, simpler and clearer computer model for user programs.
Let’s still explain how an operating system can help in the workplace through an example.
For example, if you make a network proxy software, it just receives a packet from a socket and forwards it to another socket, which doesn’t seem to have much to do with the OS, right?
But if you do it, you will find that using one thread to handle network IO, as long as it is written correctly, then even if the system is stressed, as long as the CPU can hold up, you can guarantee that the introduced latency is always within a few milliseconds; but if you use multiple threads to handle incoming/outgoing separately, then as long as the network is stressed a little, the introduced latency will increase, and soon the additional latency may break tens of milliseconds (which is actually completely (which is actually completely unusable).
Trying to figure out why this is so is impossible without a deep enough understanding of OS scheduling principles, time slicing, and other concepts. Especially, when you suddenly encounter a bug like “the system pressure is a big network latency dramatically increased”, if you don’t have a deep understanding of the operating system, you can’t even describe it accurately, and you don’t even know which direction to go for information and help, let alone debug it.
In other words, you can not build the wheel, but you need to know how the wheel is built, otherwise you do not even know how to describe the question.
And then a little bit lower, you always have to master how to install Windows, or the girl let you go to her room to fix the computer you can only refuse off!
Third, the principle of compilation
As we all know, compilation technology is one of the jewels in the history of computer science.
For the compilation principle, many programmers are confused: I will not design a new programming language, it is necessary to learn the compilation principle? What is the use of learning it?
In fact, compilation principles are not used to show off dragon slaying skills. Programmers often encounter scenarios in their work that require compilation techniques, such as
writing interface template engines.
Writing a wide variety of DSLs for projects.
Deep understanding and even developing tools like Spring, Hibernate, and Alibaba Druid.
In addition, parsing user input, preventing code injection, providing DSL for front-end engineers like React, translating one language to another like TypeScript, working flexibly through configuration files like CMake and Maven, and analyzing log files by Ops engineers and other high-level requirements, all use compilation technology.
Of course, to be honest, compilation principles are not easy to get started!
In other words, you need to prepare some basic knowledge in learning.
The learning and practice of compilation principles are usually based on a certain accumulation of knowledge about the computer compilation process, the basic working principles of computers, and even certain mathematical knowledge, which are distributed and applied in different stages of compilation principles.
Without the accumulation of this basic knowledge, you will soon be unable to continue the study at a certain stage due to the lack of merit.
So don’t start to chew the compilation principle.
Fourth, the principles of computer composition
Source from the in-depth computer composition principles
From the above diagram, you can see that the entire computer composition principle, is based on how the computer is organized to operate.
Every programmer should know Ascii code, GB2312, GBK, Utf8, Unicode and other encoding formats. If you have never come across them, there are always cases of uncompressed files with messy codes, right?
Understanding the storage format of these encodings, you will understand why there is a Chinese garbled problem.
One more example.
The example we gave above about the LRU caching algorithm is also designed with reference to the principles of computer composition.
In the world of computers, the concept of space-for-time and time-for-space often appears in complex designs.
If you want to learn more about the principles of computer composition, we recommend the book “Computer Composition: A Structured Approach”.
The book is based entirely on the concept that computers are composed of hierarchical structures, with each layer performing a defined function
1. digital logic layer
2. Microarchitecture layer
3、Instruction system layer
4、Operating system layer
5、Assembly language layer
6、Parallel architecture