Answer efficiency questions for beginners
This article is from comments from readers on my blog. He was very excited when he encountered a question raised by an active thinker. For the complete dialog, see C language and programming practice reference-n =! + B! + C! Comments on the middle and second floors.
[Problem]
Instructor, I tried % ¥ #&...... % ......, But will the program become more efficient?
[Answer]
I'm glad you asked this question. There are not many students in my physical courses. This involves our multi-dimensional understanding of efficiency.
In most cases, Efficiency refers to the efficiency of the computer, which requires time efficiency (as little as possible) and space efficiency (less memory space occupied during operation ). Most of them focus on time efficiency. Therefore, the number of lines in the source code is not the key to determining the time efficiency. As long as the final target code reduces the number of operations executed by the computer, the time will naturally be faster. The efficiency of another dimension should also be realized that it is human efficiency. Computer systems are integrated by computers and people. In fact, human efficiency is more valuable. This is critical to some companies as labor costs increase. If the problem is not too complex or the computer efficiency is low, but it is enough to meet the requirements, as a developer "person", you do not have to spend too much effort on computer efficiency. The most critical part of a system, the "bottleneck" that affects the system performance, is worth a lot of manpower and a very smart head to pursue computer efficiency. This is why many junior programmers cannot understand the necessity of learning algorithms (although good junior programmers do not have the knowledge of algorithms at all ). Your solution obviously has a high computer efficiency and a low human efficiency. Even worse, algorithms are complicated, and errors are more likely. Any project follows the rule that "Simplicity is beauty.
To answer this question, I'm glad to say a few more words.
Of course, as a learner, especially a beginner, your "low labor efficiency" is the most efficient from the perspective of learning and has a great value for training and thinking. Continue this kind of thinking and questioning!