Code Daquan Notes

Source: Internet
Author: User

A good security program is 100 times times better than a seemingly concise program. It's best to find a good plan and avoid a disaster, instead of trying to find the best solution. 1, Software Construction (1) define the problem. The problem is defined as the user embarks on what questions are raised. (2) Demand analysis. What the requirements description system should do. Define the function of the user to control the system. Can avoid the development of the controversy, rather than the programmer to define their own requirements, I do the app, because there is no complete requirements, so back to redesign. Demand is really important, and the need for stability is the holy grail of software development. However, as the longer the customer participates in the project, a change in demand is proposed, typically 25%. However, the requirements should be addressed during construction, or the costs will be higher. If the changes are too frequent, a set of change procedures should be established. Ensure that the relationship between progress, cost and demand is known to the customer. and adjust the method as needed. (3) Software construction. First, the system should be reviewed. The main building blocks are described. Each function module has less interaction with each other, and is as good as possible. Define the main class, the 802 rule, and the 80% function is done by the 20% class. Describes the design of major files and database tables. A description of the business rule. The user interface design, if not completed in the requirements phase, should be described here in detail and be modular. Resource management, including memory, threads, and handles. Security, including data encryption, and more. Performance. Scalability. Interoperability. Internationalization. Input and output. Error handling, 90% of the code is used to handle exceptions, error conditions, and rules should be defined. Fault tolerance. Buy or build, some features can be bought, such as spreadsheet processing tools. (4) Detailed design. There is also a dedicated designer to complete. Consists of 5 steps, 1, system structure. 2. Split into packages or modules. 3, decomposition into a class. 4, sub-procedures. 5, sub-program design, here can be done by the Coder (5) Coding and debugging. Programmer to complete. (6) Unit test. Programmer to complete. (7) Integration Testing (8) system Integration (9) System testing (10) System maintenance 2, class by the abstract data type (ADT) plus inheritance and polymorphism become the class, ADT will be a series of data operations set. The purpose of its design is to conceal details and so on. So you have to use private for your data. Access is used as a subroutine. Class creation Process: (1) The overall design of the class, such as data and subroutines. (2) write subroutines (3) review and test the entire class.
3, pseudo-code programming This is a programming habit that must be used later, can improve legibility, easy to maintain. It also reduces code quality, improves efficiency, and reduces the occurrence of errors. The steps are as follows: (1) Analysis subroutine function, related input and output, implied condition, processing process. Error handling, and so on. (2) First write the program header notes in English, introduce the function. Then write the pseudo-code in English according to the process. (3) Note the head and write the function head. (4) All//comments, translate comments into statements, if not translated, or relatively blurry, then you should continue to write pseudocode until clear. If it is too long, you can use the subroutine. Write a sentence or a few sentences under the line (control structure). (5) in the process of writing, the defensive programming idea should be used. 4, defensive programming in the face of absolutely not likely to happen, how to protect themselves, just like driving. such as: Check the values of external sources, such as file data. The subroutine input parameter value. Input data error How to deal with assertions: what can never happen, only in the development mode, not put into the product. For high-robustness programs, the assertion is processed first, and then the error is processed. Error handling: There are error codes to be done, return values, display errors, alarm logs, closing programs, etc. Exceptions: Also used to handle system functions or some situations that should not occur. Avoid using empty catch. You should not use catch in constructors and destructors. Debugging: As in C + +, you can use # define debug to determine that the code works only in debug mode.
This teaches the idea of programming in subroutines.
5, variable variables should be near the first use of the Declaration, the need to pay attention to the problem is: variable survival time as short as possible, the variable should have a single purpose. Variable naming: The full meaning of the variable should be described. Rules: Qualifiers such as total, sum, average, max, Min, and record should be placed behind. The cyclic word is teamcount, Teamindex. State naming: Ready, type, needed Boolean variables: Done, error, found, success, OK, available, complete enumeration named: Color_ Named in a class or interface such as red: initial uppercase subroutine: First letter lowercase member variable: M_read global variable: G_ constant: Uppercase with _ to separate objects: the first letter lowercase accessor subroutine uses set and get as prefix initials: remove non-pre-causes and keep the start and last letters. Do not use numbers.
6, type integer: except 0 error. Integer overflow. Check for intermediate result overflow. Floating-point number: Avoid using = to judge, should use the minus array: boundary
13th 1, Global data for global data, you should use accessor subroutines to replace the global data, the benefits are: (1) But to avoid the operation of the wrong (2) uniform modification of the structure is more convenient, as long as the change of a code (3) lock more convenient, directly in the sub-program lock can be. Revelation: In the app project, I put this in the Commoninfo class, all with static, but missing subroutine access. 15th 1, if else and case the place to note is that the general use of if   is to consider whether you really do not need else. The piece of initialization data that I do, if it fails, is not taken into account. That's why the problem arises. So anyway add an else clause, and if there is nothing, write a comment in it (that is, the reason for not needing else) if the judgment after the if is longer, consider using Boolean functions. 2, case with default to detect errors: if Defalut did not do other processing, and normally will not enter, then add diagnostic messages, such as write error log, or on-screen prompts. This must be noted. In Java and C + +, the case can only be integers. 3, the cycle should let people see the cycle conditions to know what this cycle is, the inside should be a black box, maintainers do not look at the sub-program can understand (1) subscript do not use i/j/k, should use the actual variables. such as Paycodeidx  divisionidx   totals such as Numpaycodes. Such an agreement can be seen at a glance, and there will be no problem, the naming method is relatively simple, plus idx can be, this is the time I used to do the test, encountered the problem, is the subscript modification and use of errors, has not been debugged, so do not have problems. (2) Loop structure should be clear, if too long should be used subroutine. The creation method, from the inside out, up to 3 layers. 17th 1, error handling and goto do not use Goto, when the need for error handling, need to jump, consider try-finnaly, jump to Finally, if it is not supported, then use the status tag. The 18th Chapter 1, the table-driven method for some logic to judge too many cases, a lot of if else composition, such as based on age to calculate information. This time you can use the table to store. In Java or C + + can use the hash table, while using key value conversion, a age group into a value. If the situation is stepped, do not use the hash table, but the ladder method. At the same time, if the situation is many, the query of the ladder table should not use sequential query, but should consider two-point search and so on. Another way is to build an index. Index a table, and the data is then placed in a table. This actually does not have the hash table to be useful. So if you use the hash table to solve the trouble, use the ladder method. The 19th Chapter 1, the Boolean type(1) For judgment, do not use 0 and a to replace the Boolean true and False. This problem should be changed, which can also be caused by the surface of the =0 and so on. For specific values, constants should be used. (2) simplified judgment expression, which is implemented by Boolean function. (3) Write a positive Boolean expression. 2, nested not more than 3 this time consider using subroutines, or use case to simplify. Otherwise the program is very difficult to understand. If the program is finished, you look very tired, then you need to improve, or the program is difficult to maintain. This is the problem I have encountered in the selection curve program in C + +. Must be simplified. 3, the complexity of the control subroutine will choose to judge as a decision point, the total decision point not more than 10, generally in more than 6 to consider simplifying the subroutine. Keep this in mind, otherwise it will be cumbersome to manage. The 20th chapter of the code after writing, to examine in detail, read the code can be detected every hour of defects than the test is about 80% higher. The check found an error only 3.5 hours, while the test took 15-25 hours. Software refactoring and rework can consume about 50% of the time in an immature software development cycle.
During the design process, the average developer introduces 1 to 3 defects per hour, with an average of 5 to 8 defects per hour during the coding phase.
Review and pair programming is an important means to improve the quality of software, special is code review, I must review two times. The 21st chapter later in the program, self-developed a scaffold, used to test the program unit, that is, test the performance of the subroutine, input and output, this must be done. For the alarm in the program, be sure to deal with it. Save the original source code when debugging and modifying the child program. Modify only one place at a time.
26th. Lifting performance (1) Use less system functions because the system functions are slow and the precision is high, and many times we don't need this high precision. As LOG2, write its value directly. (2) Reduce the amount of system computation, such as addition instead of multiplication, multiplication instead of power, use trigonometric identity substitution equivalent trigonometric function, use long or int instead of Longlong integer, replace floating number with integer, use float instead of double, use shift instead of multiply 2. (3) If the subroutine is changed to an inline function (4) When the pursuit of efficiency is not achieved, use a lower-level language, such as assembly or C
1, for the use of tools IDE, test tools, document generation tools, code automatic generation tool, you should have some understanding, to their advantage must learn. The best way to improve code quality is to learn about well-known open source software and take advantage of what others have already achieved. 2, do the unit test yourself. 31st Chapter Layout 1, for the control block such as if () {} written as if () {} So write, because many are automatically generated, directly enter the can. 2, Case writing case: ...; break; This is better for subroutines or more. Also relatively neat 3, a row do not do two operations, such as do not put ++n on the inside 4, each line only declare a variable, as close to the variable as possible the first use of the local declaration. int A;int b; this looks clearer. 5, C + + pointer in the * to close to the variable, close to the type of the first variable only valid. 6. Leave a blank line in front of the comment. Comment on a single line, which comes from the pseudo-code. 7, each function block of see to branch.  8, sub-program layout in the sub-program parameters too many, the layout is as follows: BOOL FuncName (int A; int b;) This format, otherwise it will follow the general format. 9. The function annotation of class in class layout class file is//****************************//...//*********************** sub-program annotation is//-------------------------/ /.. The view of------------------------subroutine to empty line general comment is
//... Empty line above
The 35th Chapter 1, the end of line note is only used to declare data. Include data range, unit, meaning. A declaration that includes global data. And with a look you know it's a global variable symbol. such as g_2, annotation control structure. Before you comment on the intent. If it is too long then it will appear clearer in}//if. 3, sub-program comments. The subroutine should also make a declaration in addition to the initial intent, if a global variable is used. Inside the subroutine, if the parameter is too long, you should follow the specification and comment after the definition data. 4, Javadoc This tool to use later.
33rd personality 1, to fully understand their own program, instead of using the compiler to pass, OK to cancel all warnings. 2, provide the actual situation report, otherwise the last bitter is oneself, do not need to be in front of the superior to install themselves. 3, look at others excellent open source program, this is to improve their own very important way. 4, willing to admit mistakes. 5, the project estimate, to be firm to their own position, or use overtime or something to complete, finally more than the time will end up a not to say credit. 6, the cultivation of habits is very important, excellent programmers in the first few years is very good, so the beginning should cultivate their good habits, can continue to improve. 7, when the problem, if spent half an hour has not been resolved, should spend 10 minutes to rethink the problem, try to pass it around, looking for new solutions. It takes another one hours to redesign.





Code Daquan Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.