Recently, I was asked by my friends to help others tune up a program, which is said to be my graduation thesis. I am not sure whether this thesis is a bachelor's degree or a Master's degree. It is a question about fingerprint enhancement. After I 've been away from school for so many years, I have forgotten a lot of theoretical knowledge, such as some partial derivatives, inner products, convolution ...... At first glance, what popped up in my mind was "complicated", which gave rise to a awe-inspiring feeling for science!
But after seeing the program, the mood changed completely. Let's just look at a piece of code:
For (I = 0; I <298; I ++)
{
For (j = 0; j <298; j ++)
{
N1 = n2 = 0;
For (M2 = 0; M2 <3; M2 ++) // ***** value assignment *****
{
For (M1 = 0; M1 <3; M1 ++)
{
U [N1] [n2] = tr1 [I] [J];
N2 ++;
J ++;
}
N2 = n2-3;
J = J-3;
N1 ++;
I ++;
}
N1 = n1-3;
I = I-3;
A = I + 1;
B = J + 1;
XX [a] [B] = timesx (u, I, j );
YY [a] [B] = timesy (u, I, j );
}
}
Fortunately, this is not the worst graduation thesis program I have ever seen. At least there is still alignment, and there won't be a bunch of code written in one line. However, it seems weird to see this. Why do we need to modify the cyclic variables J and I? After reading it for half a day, I realized that I wanted to copy a part of the Matrix to a temporary array. In fact, this replication is completely unnecessary. Later I spent a few hours doing a huge reconstruction of this simple program. During this period, we constantly find extremely repeated code, and even some duplicate code is inconsistent (that is, some of the copied code has been modified and corrected ). Let's take a look at this Code:
If (S [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) * (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) + 4 * s [0] [1] * s [0] [1]) <0.0)
{
{
W1 [0] [0] = W1 [1] [0] = W2 [0] [0] = W2 [1] [0] = e1 = e2= 0.0;
}
Else
If (SQRT (S [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) * (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) + 4 * s [0] [1] * s [0] [1]) = 0.0)
{W1 [0] [0] = W1 [1] [0] = W2 [0] [0] = W2 [1] [0] = e1 = e2= 0.0 ;}
Else
{
W1 [0] [0] = (2 * s [0] [1]) /SQRT (S [1] [1]-s [0] [0] + SQRT (s [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) * (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) + 4 * s [0] [1] * s [0] [1]);
W1 [1] [0] = (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) /SQRT (S [1] [1]-s [0] [0] + SQRT (s [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) * (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) + 4 * s [0] [1] * s [0] [1]);
W2 [0] [0] = (2 * s [0] [1]) /SQRT (S [1] [1]-s [0] [0] + SQRT (s [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) * (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) + 4 * s [0] [1] * s [0] [1]);
W2 [1] [0] = (s [1] [1]-s [0] [0]-SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) /SQRT (S [1] [1]-s [0] [0] + SQRT (s [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) * (s [1] [1]-s [0] [0] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) + 4 * s [0] [1] * s [0] [1]);
// *** Calculate the feature value ***
E1 = (s [0] [0] + s [1] [1] + SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) /2.0;
E2 = (s [0] [0] + s [1] [1]-SQRT (S [0] [0]-s [1] [1]) * (s [0] [0]-s [1] [1]) + 4 * s [0] [1] * s [0] [1]) /2.0;
}
Mom mia! I feel like I have entered the Matrix movie, with 0 and 1 in the eye.
Fortunately, we finally successfully disassembled and re-assembled it. In fact, it is not as complex as it is displayed. Many of them belong to repetitive computing. And because no necessary intermediate variables are introduced, such complex code will appear.
To be honest, I really admire people who write such code and can think clearly when writing such code. But at last I found some errors in this code, which is inconsistent with the formula in the paper. In fact, writing such code makes it difficult to avoid an eye-catching problem. I think the problem lies not in the students who write such code, but in Colleges and Universities!
If colleges and universities need to write a program whose complexity is A, they should teach the students the basic skills to write a program whose complexity is. To be honest, this program is not difficult from the programming perspective, but the difficulty lies in the theoretical formula. However, it is difficult for students to write programs correctly. A corresponding scenario is to publish a foreign language paper on the IEEE. The most difficult part is the theory, but if your English skills are only good study day up, then the requirement to publish a foreign language paper is simply awkward! If the Ministry of Education deems that it is necessary to publish a foreign language paper, it is necessary to strengthen the training of students in foreign languages, then we should not ask for a foreign language paper. But it is such a simple problem that the Ministry of Education cannot solve it. At least it seems to me that it is not sincere or does not do its best.
Let's go back to the writing program. I really want to ask the principal of the school, or the head of the Department: In what age have we taught students that even failed to pass the code style? How did they graduate? I don't expect undergraduates to do anything about design patterns, but this series of S [0] [0]-s [0] [1] + SQRT (...) there are also those unreasonable code for modifying the circular variables. Do the teachers who teach them the computer look ashamed? If the students I teach write such code in my graduation thesis, I will simply resign and forget it-no face to face!
I also know that there are too few courses invested in computer programming in the current university, and there is a big gap in the basic computer skills of university freshmen. There are various objective obstacles. In this case, don't drag the ox to the tree and catch the duck to go on the shelves. Don't let them choose a graduation thesis topic for programming and solving fingerprint enhancement! The result of knowing that it cannot be done is a word "mixed ".
I used to think that this program was written by my colleagues who solved the problem. I am also embarrassed to write it out for fear of cracking down on others' self-esteem. After chatting with him, I realized that the program was originally provided to him by his mentor, and the author was a graduate of the previous session. I'm not welcome, but it's the author. Alas, I feel that this problem is already a norm. When my girlfriend was studying it, I also heard a lot of such things. A lot of people use programs that have been written by their mentors, that are nonsense, that have incorrect execution results, or that cannot be compiled at all, repair, modification, and random adjustment of several parameters, and addition of several methods that are not actually called at all, finally graduated like his graduated senior brother and sister. After the change, even worse programs will be spread. Is the result expected by the Ministry of Education? I believe that this level is definitely not acceptable to a commercial software company!
My girlfriend said I was complaining again. Yes, I was complaining! A comrade commented on me two days ago: "strange, strange, strange ...... The design pattern is to improve the performance "cloud, in fact, I was very depressed at that time. The situations I mentioned are not serious. If you compare them with my example today. These people have graduated from the company. Do you expect them to understand the design model? They don't mess up your well-written code, well-designed framework, and well-developed third-party tools. You should read "Amitabha (Delete more than words here,. Even the best design model cannot handle the random Copy & paste. Let alone layer-5 nested loops, plus loop variables for internal loops to modify external loops, a long string of calls in the IF statement, and a completely fearless repeated call.
I also don't want to complain about it any more. I finally complained about it again:
Major colleges and universities should never use the C ++ syntax to teach their students the keywords of C language, and read jokes! I felt depressed when I was reading this program. Why is there a long string of variable declarations before each function, even if it was used at the end. It turns out that this is a C file, not a CPP file! Other code I have encountered before is similar to the following:
Int func1 (A, B)
Int;
Float B;
{
Return (A + B );
}
I don't know if you see the fossil like me? Do not argue with me for reasons like "using C better than C ++, and writing underlying code should use C instead of C ++, I believe that the reason why students who write such bad code Choose C instead of C ++ is definitely not for this reason. The first reason is that the efficiency of such programs cannot be solved by using the C compiler, And the second reason is that I believe they are even more stupid and have no such reason.
Don't talk about it. Open another article and write something else.
P.s .:
@ Dudu: It seems that if you open a complaint area, I will write a lot of articles. Click it!