I won’t wait for everyone’s answer to this question. I believe everyone understands that I am not asking this out of boredom. The syntax of JS itself is not difficult, but what is the difficulty? Mainly lies in the following points:
1. How to abstract concrete problems
is to face a very specific problem For example, in an online shopping mall, the various interactions within it are complicated. So how do you go about writing it? The front-end architecture also needs to be designed. It depends on whether you understand the business of the online mall and whether you can take various situations into consideration. If various problems arise, how are they caused?
2. How to control the complexity of the code
I often see people saying that you cannot write more than a few lines of code in a function, but in actual development, a certain number of lines of code cannot be written in a function. The complexity of a single business is that so much code must be written. This requires good code writing habits and ideas, so that it can be easily maintained, modified, and upgraded in a single method.
3, the meaning of past codes
Code is not text. If you read an article you wrote three months ago and read it three months later, you will still understand what you wrote. But the code is not. In many cases, it does not take 3 months. If you write the code 3 days ago, if you look at it 3 days later, you will have no idea what it means.
When you read the text, you directly read the meaning. But when you look at code, especially other people's code (I'm only talking about myself, not the talented ones), most of the time you have to translate it into Chinese in your mind, and then connect them to understand the meaning of this code. But what does this code mean when placed in the entire project? Who is calling it? What situation was it written to handle? I still don't know. This situation often occurs when you join an existing multi-person collaboration project. You look at it for a long time and don’t know why others wrote this, and then you don’t dare to change or delete it.
4, the limitations of the human brain.
It is basically difficult for the brains of ordinary people like you and me to process an N-variable program like a program. It is impossible to look at a piece of code and understand its operation process in the mind. Think about it again and you will know if there is something wrong with it. The human brain is not good at this. For example, if you are asked to calculate 288*193*435, you must use a calculator. We won’t mention those prodigies, because none of us are.
The program requires that all variables and codes must be correct. If one is wrong, it means they are all wrong. But people like you and me cannot load and simulate the entire calculation process in our minds like memory. In fact, I just don’t have enough brain power to figure it out. So you need to debug, you need console.log, you need to refresh with F5 to see the results. Therefore, biological limitations make programming inherently difficult, and this fact exists objectively.
5, the problem of language itself.
It’s just that JS is not an intuitive natural language. You can’t just say what you see. First of all, you need to know the grammar, which is not difficult. But you need to be able to use JS language to describe the problems and needs you see. There is a process of adaptation and conversion here.
Whether the JS language is difficult or not, that’s all. I just hope everyone can understand why it is difficult.
The above is the detailed content of Why is js so difficult. For more information, please follow other related articles on the PHP Chinese website!