1. Whether code specification is required
Consider the following arguments and refute/support for whether you need to have code specifications:
These norms are the result of the bureaucratic system of wasting everyone's programming time, affecting people's development efficiency, waste of time things.
Wrong. Code specification is designed to facilitate the communication and review of the programmer community. After all, a project is mostly in the form of a team.
I am an artist, a craftsman, I have my own norms and principles.
No, the coding style is not a coding specification, and the coding specification includes both the coding style and other specifications, not just the code format. For example, a function like "return success/failure should use an integer as the return value", such that the rule is not in the coding style. Have their own style can, but not because their style violates the code specification.
Norms can not be forced to all, should allow many exceptions.
No, the specification is called specification, is an industry code of conduct, if allowed exceptions can not be called norms.
I'm good at coding, you can listen to me.
No, the norm should not be decided by a person, but by the majority of people, and can withstand the test to be called norms.
2. Code review
I examined Wang Nequan classmate, who said it was my roommate. The source code is as follows:
#include <stdio.h>#include<stdlib.h>#include<time.h>Main () {inta,b,op,os;aq1:printf ("Choose the algorithm you want to challenge \ n");p rintf ("1. Addition 2. Subtraction 3. Multiplication 4. Division \ n"); scanf ("%d",&op);Switch(OP) {aq: Case 1: Srand ((unsigned) time (NULL)); a=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d +%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d +%d =%d\n\n\n", a,b,a+b);Gotoaq1;}ElseGotoaq; Break; at: Case 2: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d-%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d-%d =%d\n\n\n", a,b,a-b);Gotoaq1;}ElseGotoat ; Break; AQ2: Case 3: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d *%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d *%d =%d\n\n\n", a,b,a*b);Gotoaq1;}ElseGotoaq2;aq3: Case 4: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d/%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d/%d =%d\n\n\n", a,b,a/b);Gotoaq1;}ElseGotoaq3; Break;}}
Does the code work?
Job
Does the code conform to requirements and specifications?
Yes
is the code design considered comprehensive?
Missing the case of having a denominator of zero.
All the code is easy to understand?
Not that the individual level is limited and not fully understood, but most of it can be understood
Do you have redundant or duplicated code?
No
As much as possible, modular code?
Yes
Can any global variable be replaced?
Yes
Can the code be tested?
Yes
Is there any useless code to erase?
No.
I reviewed Wang Nequan's code, found a lot finer than me, and learned some ideas, and his code considered a single operation, suitable for students who wanted to strengthen the subtraction single computational capability. worthy of reference.
Job Three: Code specification, code review, PSP